Choose order to execute JUnit tests

后端 未结 8 1057
执笔经年
执笔经年 2020-12-11 03:32

I wanted to choose the order to execute the JUnit tests. I have 4 classes with several test methods in it, my goal is to execute, for instance, method Y of class A, then met

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 03:42

    The JUnit answer to that question is to create one test method like this:

      @Test public void testAll() {
           classA.y();
           classB.x();
           classA.z();
      }
    

    That is obviously an unsatisfying answer in certain cases (where setup and teardown matter), but the JUnit view of unit testing is that if tests are not independant, you are doing something wrong.

    If the above doesn't meet your needs, have a look at TestNG.

提交回复
热议问题