<legend id='qVAYH'><style id='qVAYH'><dir id='qVAYH'><q id='qVAYH'></q></dir></style></legend>
    • <bdo id='qVAYH'></bdo><ul id='qVAYH'></ul>
    <tfoot id='qVAYH'></tfoot>

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

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

        如何使用 Junit 按顺序运行测试方法

        How to run test methods in order with Junit(如何使用 Junit 按顺序运行测试方法)
        • <small id='jJRFA'></small><noframes id='jJRFA'>

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

              <tbody id='jJRFA'></tbody>
          2. <legend id='jJRFA'><style id='jJRFA'><dir id='jJRFA'><q id='jJRFA'></q></dir></style></legend>
              <bdo id='jJRFA'></bdo><ul id='jJRFA'></ul>

                  <tfoot id='jJRFA'></tfoot>
                  本文介绍了如何使用 Junit 按顺序运行测试方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 JUnit 和 Selenium Webdriver.我想按照我在代码中编写它们的顺序运行我的测试方法,如下所示:

                  I am using JUnit and Selenium Webdriver. I want to run my test methods in order as how I write them in my code, as below:

                  @Test
                  public void registerUserTest(){
                      // code
                  }
                  
                  @Test
                  public void welcomeNewUserTest(){
                      // code
                  }
                  
                  @Test
                  public void questionaireNewUserTest(){
                      // code
                  }
                  

                  但它不起作用,它总是按这个顺序执行我的测试方法:

                  But it doesn't work, it always executes my test methods in this order:

                  welcomeNewUserTest()
                  registerUserTest()
                  questionaireNewUserTest()
                  

                  如果我用后缀 Test 命名我的方法,我会在某处读到答案,然后 JUnit 会按照我在代码中对它们的排序方式执行它们.显然,这行不通.

                  I read an answer somewhere if I name my method with suffix Test, then JUnit would execute them in order as how I order them in code. Apparently, this doesn't work.

                  有什么帮助吗?谢谢

                  推荐答案

                  所以对于像这样的测试——步骤相互依赖——你应该真正将它们作为一个单元来执行.你真的应该做这样的事情:

                  So for tests like these - where the steps are dependent on each other - you should really execute them as one unit. You should really be doing something like:

                  @Test
                  public void registerWelcomeAndQuestionnaireUserTest(){
                      // code
                      // Register
                      // Welcome
                      // Questionnaire
                  }
                  

                  正如@Jeremiah 下面提到的,有一些独特的方法可以使单独的测试无法预测地执行.

                  As @Jeremiah mentions below, there are a handful of unique ways that separate tests can execute unpredictably.

                  既然我已经说过了,这就是你的解决方案.

                  Now that I've said that, here's your solution.

                  如果你想要单独的测试,你可以使用 @FixMethodOrder 然后按 NAME_ASCENDING 执行.这是我知道的唯一方法.

                  If you want separate tests, you can use @FixMethodOrder and then do it by NAME_ASCENDING. This is the only way I know.

                  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
                  public class TestMethodOrder {
                  
                      @Test
                      public void testA() {
                          System.out.println("first");
                      }
                      @Test
                      public void testC() {
                          System.out.println("third");
                      }
                      @Test
                      public void testB() {
                          System.out.println("second");
                      }
                  }
                  

                  将执行:

                  testA(), testB(), testC()

                  在你的情况下:

                  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
                  public class ThisTestsEverything{
                  
                      @Test
                      public void T1_registerUser(){
                          // code
                      }
                  
                      @Test
                      public void T2_welcomeNewUser(){
                          // code
                      }
                  
                      @Test
                      public void T3_questionaireNewUser(){
                          // code
                      }
                  
                  }
                  

                  这篇关于如何使用 Junit 按顺序运行测试方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

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

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

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

                    1. <tfoot id='XcA4F'></tfoot>

                          <bdo id='XcA4F'></bdo><ul id='XcA4F'></ul>
                              <tbody id='XcA4F'></tbody>