When you write your unit tests you must use some kind of assertions. I think that most of you will agree with me on that the asserts that comes with the JUnit aren’t the easiest and most readable ones.

So, some time ago I started to use a Hamcrest matcher library. It was a great progress, as I was able to move away from JUnit’s unintuitive: assertEquals(11.0, actual). I mean, if you try to read it out loud it doesn’t seem very logical:
“assert equals 11 is actual,
“assert equals 11 as actual?.

Moreover, the expected value is the first argument and the actual one is the latter which also makes it harder to understand.

And here comes the *Hamcrest* matcher which brings a fluent API consisting of a lot of useful methods.

Continue reading

By default, Maven’s test plugin Surefire doesn’t scan files for @Test annotations, but rather takes only the files which class names ends with “Test” or “TestCase”.

I use both: unit tests and integration tests. I execute the latter using Arquillian framework, so it looks just like pure JUnit test. However, I prefer to name them with the “IT” suffix which means that they’re no longer recognized by Surefire plugin as test files.
If you want Maven to execute such tests, you need to give him a hint (using appropriate configuration element) to scan also for the *IT classes:

<configuration>
    <includes>
        <include>%regex[.*[Test|IT].class]</include>
    </includes>
</configuration>

Just remember that the regex works only on *.class files. It also overrides the default rules (which means that you need to add the *Test and/or the *TestCase suffix to scan for default test classes.)