How to execute junit test cases parallely using maven surefire plugin?

Junit test parallel execution can bring down the test execution time considerably. The only condition is that your test cases must be independent. The state shall not be shared across test cases. Today, I shall share a maven project with parallel test execution configured using maven surefire plugin. The complete source code can be found […]
Continue reading…

 

Separate unit and integration testcases using JUnit Category.

This post is about separating Unit and Integration testcases using JUnit category and running those separately using maven. This post in NOT about moving unit and integration testcases into separate test source folders. With the introduction of org.junit.experimental.categories.Category annotation in JUnit 4.x we are in a position to separate integration testcases using annotation. Basically Category […]
Continue reading…

 

JUnit Best Practices – Use expected exception instead of catching the exception

Use JUnit expected exception feature to test a unit that might throw an exception in given situation or for a given input. package com.ourownjava.unit.under.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.List; import org.junit.Before; import org.junit.Test; import com.ourownjava.exception.NoAppleException; import com.ourownjava.model.Apple; /** * * @author Sanju Thomas * */ public […]
Continue reading…

 

JUnit Best Practices – Use correct assertion

Always do a strong assertion against the returned state from a unit. Avoid assertion like the collection size shall be greater than zero. A better assertion could be checking the size of the collection and content of the collection. Complete source code can be found here. package com.ourownjava.unit.under.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import […]
Continue reading…

 

How to add JUnit library into a java project in Eclipse?

1. Right click on the project and select properties. 2. In the properties window, go to Java Build Path -> Libraries 3. Click on “Add Library” 4. In the Add Library window, select JUnit and click Next Button. 5. In the next window select the desired JUnit version. Select JUnit 4 for annotation driven tests […]
Continue reading…