• <bdo id='XwlRX'></bdo><ul id='XwlRX'></ul>

  • <i id='XwlRX'><tr id='XwlRX'><dt id='XwlRX'><q id='XwlRX'><span id='XwlRX'><b id='XwlRX'><form id='XwlRX'><ins id='XwlRX'></ins><ul id='XwlRX'></ul><sub id='XwlRX'></sub></form><legend id='XwlRX'></legend><bdo id='XwlRX'><pre id='XwlRX'><center id='XwlRX'></center></pre></bdo></b><th id='XwlRX'></th></span></q></dt></tr></i><div id='XwlRX'><tfoot id='XwlRX'></tfoot><dl id='XwlRX'><fieldset id='XwlRX'></fieldset></dl></div>

    <tfoot id='XwlRX'></tfoot>
      <legend id='XwlRX'><style id='XwlRX'><dir id='XwlRX'><q id='XwlRX'></q></dir></style></legend>

      <small id='XwlRX'></small><noframes id='XwlRX'>

      1. TestNG 依赖于不同类的方法

        时间:2023-10-01

        <small id='YLamc'></small><noframes id='YLamc'>

            <bdo id='YLamc'></bdo><ul id='YLamc'></ul>

                1. <legend id='YLamc'><style id='YLamc'><dir id='YLamc'><q id='YLamc'></q></dir></style></legend>
                2. <i id='YLamc'><tr id='YLamc'><dt id='YLamc'><q id='YLamc'><span id='YLamc'><b id='YLamc'><form id='YLamc'><ins id='YLamc'></ins><ul id='YLamc'></ul><sub id='YLamc'></sub></form><legend id='YLamc'></legend><bdo id='YLamc'><pre id='YLamc'><center id='YLamc'></center></pre></bdo></b><th id='YLamc'></th></span></q></dt></tr></i><div id='YLamc'><tfoot id='YLamc'></tfoot><dl id='YLamc'><fieldset id='YLamc'></fieldset></dl></div>
                  <tfoot id='YLamc'></tfoot>

                    <tbody id='YLamc'></tbody>

                3. 本文介绍了TestNG 依赖于不同类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  @Test 注释的 dependsOnMethods 属性在要依赖的测试与具有此注释的测试属于同一类时正常工作.但是如果要测试的方法和依赖的方法在不同的类中,则不起作用.示例如下:

                  The dependsOnMethods attribute of the @Test annotation works fine when the test to be depended upon is in the same class as that of the test that has this annotation. But it does not work if the to-be-tested method and depended-upon method are in different classes. Example is as follows:

                  class c1 {
                    @Test
                    public void verifyConfig() {
                      //verify some test config parameters
                    }
                  }
                  
                  class c2 {
                    @Test(dependsOnMethods={"c1.verifyConfig"})
                    public void dotest() {
                      //Actual test
                    }
                  }
                  

                  有没有办法绕过这个限制?一种简单的方法是在 class c2 中创建一个调用 c1.verifyConfig() 的测试.但这将是太多的重复.

                  Is there any way to get around this limitation? One easy way out is to create a test in class c2 that calls c1.verifyConfig(). But this would be too much repetition.

                  推荐答案

                  把方法放在一个group中,使用dependsOnGroups.

                  Put the method in a group and use dependsOnGroups.

                  class c1 {
                    @Test(groups={"c1.verifyConfig"})
                    public void verifyConfig() {
                      //verify some test config parameters
                    }
                  }
                  
                  class c2 {
                    @Test(dependsOnGroups={"c1.verifyConfig"})
                    public void dotest() {
                      //Actual test
                    }
                  }
                  

                  建议在 @Before* 中验证配置并在出现问题时抛出,这样测试就不会运行.这样,测试就可以专注于测试.

                  It is recommended to verify configuration in a @Before* and throw if something goes wrong there so the tests won't run. This way the tests can focus on just testing.

                  class c2 {
                    @BeforeClass
                    public static void verifyConfig() {
                      //verify some test config parameters
                      //Usually just throw exceptions
                      //Assert statements will work
                    }
                  
                    @Test
                    public void dotest() {
                      //Actual test
                    }
                  }
                  

                  这篇关于TestNG 依赖于不同类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:TestNG:一个@Test 有多个@DataProvider 下一篇:在 Spring Boot IntegrationTest 上禁用 @Schedule

                  相关文章

                  最新文章

                  <legend id='P07Y6'><style id='P07Y6'><dir id='P07Y6'><q id='P07Y6'></q></dir></style></legend>

                  <small id='P07Y6'></small><noframes id='P07Y6'>

                  1. <i id='P07Y6'><tr id='P07Y6'><dt id='P07Y6'><q id='P07Y6'><span id='P07Y6'><b id='P07Y6'><form id='P07Y6'><ins id='P07Y6'></ins><ul id='P07Y6'></ul><sub id='P07Y6'></sub></form><legend id='P07Y6'></legend><bdo id='P07Y6'><pre id='P07Y6'><center id='P07Y6'></center></pre></bdo></b><th id='P07Y6'></th></span></q></dt></tr></i><div id='P07Y6'><tfoot id='P07Y6'></tfoot><dl id='P07Y6'><fieldset id='P07Y6'></fieldset></dl></div>
                    <tfoot id='P07Y6'></tfoot>
                        <bdo id='P07Y6'></bdo><ul id='P07Y6'></ul>