November 2024
Intermediate to advanced
300 pages
7h 12m
English
JUnit tests don’t run in their declared (top to bottom) order. In fact, they don’t run in any order that you’d easily be able to determine or depend on, such as alphabetically. (They’re likely returned in the order that a call to java.lang.Class.getMethods() returns, which is “not sorted and not in any particular order,” per its Javadoc.)
You might be tempted to think you want your tests to run in a specific order: “I’m writing a first test around newly created accounts, which have a zero balance. A second test can add $100 to the account, and I can verify that amount. I can then add a test that runs third, in which I’ll deposit $50 and ensure that the new balance is $150.”
While JUnit 5 provides ...
Read now
Unlock full access