Freitag, 4. Mai 2018

Java UNIT Test Exception Handling with @Rule

A nice way to get rid of manual Exception handling in JUnit Tests is this:

 public ExpectedException thrownException = ExpectedException.none();

 public void testSomething() {

      // given
        thrownException.expectMessage("my expected msg");
        thrownException.reportMissingExceptionWithMessage("my custom msg");

      /*  possibly doing setup of mocks which throw the Exception... */

      // when / then
      testee.doSomething(); // throws the Exception...

Keine Kommentare:

Kommentar veröffentlichen

DOCKER - No Space Left on Device // How to clean Docker on Linux

Sometimes Docker will simply claim to much space. Time for a clean up ;) docker system prune -a -f