Random Allsorts: JUnit 4.11 - What's new? Test execution order
owever, even with this, there is still a problem. The algorithm used to calculate the deterministic order is based on the hashCode of the method name, it's pretty obscure. This means that if I have a problem with ordering then I can't easily fix it. For instance, the hashCode of "secondTest" is 423863078 and "thirdTest" is -585354599. Which means that thirdTest will be executed before secondTest. But if I want for whatever reason to execute thirdTest after secondTest, I have to rename thirdTest to something with a hashCode of greater than 423863078. Yuck. But, there is a solution.
@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ExecutionOrderTest { @Test public void firstTest() { System.out.println("firstTest"); } @Test public void secondTest() { System.out.println("secondTest"); } @Test public void thirdTest() { System.out.println("thirdTest"); } public static void main(String[] args) { JUnitCore.runClasses(ExecutionOrderTest.class); } }Read full article from Random Allsorts: JUnit 4.11 - What's new? Test execution order
No comments:
Post a Comment