Java, JUnit, Mockito, Unit test

Checking parameter of a mocked method call with Mockito

If you are using Mockito, it is sometimes useful to check the parameter state of a method passed to a mocked method call. I use it in the following cases DAO method, like create or update is called in the code. I  want to check, if the entity has been set correctly before writing into… Continue reading Checking parameter of a mocked method call with Mockito

Advertisement
eclipse, Java, Unit test

Using logging in your unit test

When running unit test, you are not supposed to be checking the logs, generated by the test framework. One of the first principles of the test driving development paradigm is, that you should be able to run your tests automatically, without any developer interaction. You also should not be forced to check any output besides… Continue reading Using logging in your unit test

JUnit, Mockito

How to use @Rule annotation instead of the expected keyword to unit test exceptions

The usual way for unit testing expected exceptions looks like this: @Test(expected = ConfigurationException.class) It has although the following disadvantages: you can not check details of the exception, like message or cause you can not do anything with the exception It is a better solution to use the @Rule annotation from JUnit. import org.hamcrest.core.StringContains; import org.junit.Assert;… Continue reading How to use @Rule annotation instead of the expected keyword to unit test exceptions