Tags » JUnit

use log4j in junit test assertions

I need to confirm that some error/warnings are logged in the code being tested. The logger is usually private static final that we cannot get from the junit. 70 more words


Fun code

Although I’m not sure when it could be applicable in production to write “fun code”, I think that there is a lot of room for creativity in this area when writing tests.  262 more words


Great Expectations

What’s the best way to handle expected exceptions in JUnit?

If you want to inspect the contents of the exception and make assertions against it then there is only one clean way; Use the ExpectedException JUnit Rule. 171 more words

Clean Test Code

Why I spy

Spy is a mocking concept used to mock/stub parts of a class (“partial mocking”).
Should we use it? And if so, when?

From one perspective, gazing from an… 296 more words


JodaTime and JUnit

JUnit Rules are powerful things. There are all sorts of things you can do with a Rule that makes test code cleaner and less error-prone. 655 more words

Clean Test Code

Proper way to access file resources in junit tests

As I was refactoring some JUnit tests recently I was reminded of an important fact on the proper way to read in a file.
In  172 more words