Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JUnit execute test cases sequentially?

In this post, I asked a small question as part of a bigger problem. Since I didn't get responses yet, I put my question here:

Is it reasonable to suppose that JUnit executes test cases sequentially: a test case ends befores the next one starts. Does it differ between JUnit versions (my priority is on JUnit4)? And if not, is there a simple way to force JUnit to execute tests sequentially?

Thank you

like image 446
H-H Avatar asked Sep 01 '11 08:09

H-H


People also ask

Are JUnit tests run sequentially?

1. Overview. By default, JUnit runs tests using a deterministic but unpredictable order (MethodSorters. DEFAULT).

How do you make JUnit test cases run in order?

In JUnit, you can use @FixMethodOrder(MethodSorters. NAME_ASCENDING) to run the test methods by method name, in lexicographic order.

Do unit tests run in order Java?

By default, unit testing libraries don't try to execute tests in the order that occurs in the source file.


1 Answers

Yes, by default I believe it runs tests sequentially.

JUnit 4.6 introduced an experimental ParallelRunner to run tests in parallel - I don't know of its current status. I would expect parallelism to remain an "opt-in" feature by default though. (Judging by other answers, it looks like this is now here to stay but in a slightly different form - and still opt-in.)

like image 175
Jon Skeet Avatar answered Sep 18 '22 08:09

Jon Skeet