[DEECo] sw testing - mockups

Jaroslav Keznikl keznikl at d3s.mff.cuni.cz
Wed Sep 4 09:39:26 CEST 2013


Hi guys,
I just wanted to share some the experience of the last few weeks (and also
to have a record for myself):

- 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) - this is
what we already do

- to test such a highly decomposed code (in jDEECo, you put an instance of
KRepository into an instance of KManager which you put into Runtime, etc. -
you get the picture), it is very convenient to use some mock-up library.
And this is exactly what I wanted to share: I have been really pleasantly
surprised by *mockito*. It is really easy to write the 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.

Web:
        https://code.google.com/p/mockito/
Maven:
        <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
    </dependency>

Here are some other unit-testing tools that helped me:
- http://www.stefan-birkner.de/system-rules/ for testing System calls
     <dependency>
         <groupId>com.github.stefanbirkner</groupId>
         <artifactId>system-rules</artifactId>
         <version>1.3.1</version>
     </dependency>

- http://junit-addons.sourceforge.net/ for things like FileAssert
(comparing text/binary files with nice reports), ListAssert (the same for
lists).
     <dependency>
         <groupId>junit-addons</groupId>
         <artifactId>junit-addons</artifactId>
         <version>1.4</version>
     </dependency>

- I also use a modification of the DynamicSuite class to invoke all the
tests in a package (and subpackages) -
http://www.anzaan.com/2012/01/automatic-unit-testing-test-packages-recursively-in-junit/.
Note that I had to fix small bugs in the code before actually using it.

Have fun
Jarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://d3s.mff.cuni.cz/pipermail/deeco/attachments/20130904/a5c3168f/attachment.html>


More information about the DEECo mailing list