helloopensource

 

JUnit

Page history last edited by paulo 1 yr ago

 

 

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:

  1. Open Eclipse for Java (helloJUnit)
  2. Create a Java Project - helloJUnit
    1. File/New/Project…
  3. Create a JUnit Test Case (name it SillyTest)
    1. File/New/JUnit Test Case 
  4. Add JUnit library to your project (if you have the error marks as in the following picture)
    1. 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. 
  5. Add the following methods to your SillyTest Test Case.
    1.      public void testTrue() throws Exception {

                assertTrue(true);

           }

          

           public void testSum() throws Exception {

                assertEquals(3, 1+2);

           }

  6. Run JUnit Test
  7. 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.