JUnit testing – part I – setup with simple example

JUnit is one of available Java libraries we can use to test our application code.  Let’s get started by buliding simple project using Maven.

Generating project with JUnit support

Go generate simple Java artifact using Maven, which can be done quite easilly using command line.

mvn archetype:generate -DgroupId={GROUP_ID} -DartifactId={ARTIFACT_ID} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Just execute upper line in your console, giving it some {GROUP_ID} and {ARTIFACT_ID}. Make sure you haven Maven installed and on your path, so that you can run it as described. This is not related to JUnit testing, just give it any values, I will use com.mydomain as {GROUP_ID}, and junit-demo as {ARTIFACT_ID}. That should generate new java project ready to demo JUnit tests. You can import generated application into IDE of your choice.

Continue reading

Advertisements