Hello JUnit using Eclipse
This Tutorial will show you how to write a simple JUnit Test Case using JUnit and Eclipse for Java IDE.
Main Learning's
After following this tutorial you will learn how to:
- Create a JUnit Test Case
- Add JUnit library to a Java project build path
- Run a JUnit Test Case
Versions used:
- Eclipse SDK 3.2.2
- JDKversion 1.5.0_12
- JUnit 4
Assumptions:
The JDK is properly installed
Eclipse for Java is properly installed.
Tutorial Steps:
- Open Eclipse for Java (helloJUnit)
- Create a Java Project - helloJUnit
- File/New/Project…

- Create a JUnit Test Case (name it SillyTest)
- File/New/JUnit Test Case


- Add JUnit library to your project (if you have the error marks as in the following picture)

- One way of adding JUnit library with Eclipse is to click on the error mark and select the “Add JUnit to the build path” option.

- Add the following methods to your SillyTest Test Case.
-
public void testTrue() throws Exception {
assertTrue(true);
}
public void testSum() throws Exception {
assertEquals(3, 1+2);
}

- Run JUnit Test

- The Green Bar

Why is this unit test silly?
You don’t need to test the java language (true, 1+2=3). Instead your unit tests should be testing functional code that you write.
Comments (0)
You don't have permission to comment on this page.