How-to articles, tricks, and solutions about JUNIT4

How to assert that a certain exception is thrown in JUnit tests?

To assert that a certain exception is thrown in a JUnit test, you can use the @Test annotation's expected attribute. Here's an example:

How to run test methods in specific order in JUnit4?

In JUnit 4, you can use the @FixMethodOrder annotation to specify the order in which test methods should be executed.

How to test that no exception is thrown?

To test that no exception is thrown in a Java method, you can use the assertDoesNotThrow method from the org.junit.jupiter.api.Assertions class (part of the JUnit 5 library).