Hello World from OSS Silicon Valley


HowToUse/JUnit/4.8


_ Prerequisite

(Mandatory)

  • Java SDK installation

(Optional)

The explanation in this page assumes the following.

_ Install&Setup

Step.1
(We can use maven)

_ HowToUse

_ Create project.

Step.1
Launch Cygwin.
Step.2
Create the most simple maven project.
$ mvn archetype:create \
 -DgroupId=org.test \
 -DartifactId=project
CreateMavenProject_fig1.png
Step.3
Sample production code App.java and AppTest.java will be created. You can execute testing by the following command.
$ mvn test
CreateMavenProject_fig2.png

_ Import mvn project to eclipse

Step.1
Luanch eclipse.
Step.2
Select File -> Import.
ImportMavenProject_fig1.png
Step.3
Select "Existing Maven Projects" and click "next" button.
ImportMavenProject_fig2.png
Step.4
Click "Browse" button and select created maven project folder.
ImportMavenProject_fig3.png
ImportMavenProject_fig4.png
Step.5
Click "Finish" button. And you have imported eclipse project.
ImportMavenProject_fig5.png

_ Prepare source code.

Step.1
Create sample production code, "Calc" as follows. sample code - Calc
CreateCode_fig1.png
Step.2
Select "File"->"New"->"JUnit Test Case" (lower one).
CreateCode_fig2.png
Step.3
Select "New JUnit 4 test" and click "Finish" button.
CreateCode_fig3.png
Step.4
When the JUnit 4 is not on the build path, eclipse ask if we setup it or not. Here, we choose "Not now" and click "OK" button. We will use maven later for this.
CreateCode_fig4.png
Step.5
Open POM.xml and edit it as following.
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.8.1</version>
  <scope>test</scope>
</dependency>

sample code - POM.xml

Step.6
Execute the following command. Maven download JUnit4 and setup it to the build-path based on the description in POM.xml.
$ cd <Maven project directory>
$ mvn test
CreateCode_fig7.png

Now we have JUnit in project, too.

CreateCode_fig6.png

_ Author

S.Yatsuzuka