Category Archives: JUnit

Maven Doesn’t Execute All JUnit Tests by Default

We as developers write many unit tests. The CI pipeline will run all tests with every build. We trust that, if the status is green, everything should be okay.

But what if the unit tests should have failed? I recently learned that Maven does not execute all tests by default.

Consider this simple class:

public class MyTests {

    @Test
    public void firstTest() {
        assertEquals(2, 1 + 1);
    }

    public static class NestedTests {

        @Test
        public void secondTest() {
            assertEquals(3, 1 + 1);
        }
    }
}

We see that firstTest should succeed and secondTest should fail. Continue reading

error