Skip to main content

Posts

Showing posts from May, 2013

Testing in Java

I would like to share a couple of useful tips and links for (unit) testing in Java (focusing on jUnit): To have your code testable, it is a good idea to use dependency injection (e.g., all the critical references are passed in the constructor)To test such a highly decomposed code, it is very convenient to use some mock-up library. I have been really pleasantly surprised by mockito (https://code.google.com/p/mockito/). It is really easy to create your mocks and the unit tests are then so much easier to write (and can be so much more fine-grained) - I definitely recommend to check it out.
<dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.9.5</version> </dependency> For testing System calls, I like to use SystemRules for jUnit (http://www.stefan-birkner.de/system-rules/)
<dependency> <groupId>com.github.stefanbirkner</groupId> <artifactId>system-rules</art…