A nice way to get rid of manual Exception handling in JUnit Tests is this:
@Rule
public ExpectedException thrownException = ExpectedException.none();
@Test
public void testSomething() {
// given
thrownException.expect(MyExpectedException.class);
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...
}
Abonnieren
Kommentare zum Post (Atom)
NEW BLOG! http://cleancode.consulting/
Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at http://cleancode.consulting/
-
Resolve a Merge Conflict in GIT with IntelliJ Let us assume you are using Bitbucket or a similar tool to administrate and host your GI...
-
Just create a package-info.java file for your package in which you have your POJO: @javax.xml.bind.annotation.XmlSchema(namespace = ...
Keine Kommentare:
Kommentar veröffentlichen