I am using Junit for unit testing in my project. I need to make ordering junit test classes execution or make one of them run last when i run the package containing all test classes or when those are running when doing a maven install. thank you for your help.
答案 0 :(得分:1)
Unit test has to be Unit
. If you are trying to make some sort of unit tests which are dependent on each other then its a bad idea.
Although you can use @BeforeClass
or @AfterClass
Annotation for setting up your configuration for test or cleanup code respectively.
答案 1 :(得分:1)
By design, JUnit does not specify the execution order of test method invocations. Until now, the methods were simply invoked in the order returned by the reflection API. However, using the JVM order is unwise since the Java platform does not specify any particular order, and in fact JDK 7 returns a more or less random order. Of course, well-written test code would not assume any order, but some does, and a predictable failure is better than a random failure on certain platforms.
JUnit 4.11 will by default use a deterministic, but not predictable, order (MethodSorters.DEFAULT). To change the test execution order simply annotate your test class using @FixMethodOrder and specify one of the available MethodSorters:
@FixMethodOrder(MethodSorters.JVM): Leaves the test methods in the order returned by the JVM. This order may vary from run to run.
@FixMethodOrder(MethodSorters.NAME_ASCENDING): Sorts the test methods by method name, in lexicographic order.