• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:


what are the steps involved in junit to check each modules

could you explain with simple
Manikandan Thiagarajan
Manikandan Thiagarajan
3 Solutions
JUnit is a unit testing package.  Typically you'll want to test one class at a time.  For example lets say I have the following simple class.

public class Calculator
  public int add( int x, int y )
    return x + y;

If I was to write some test code for this, I'd like to verify that the add method does indeed add numbers, so I'd create a simple test class such as.

public class TestCalculator
  extends junit.framework.TestCase
  private Calculator _calculator;

  protected void setUp ()
    _calculator = new Calculator();

  public void test_add ()
    assertEquals( 1, _calculator.add( 0, 1 ) );
    assertEquals( 2, _calculator.add( 1, 1 ) );

The setup routine is used to initialise the fixture (i.e. the thing you are testing).  The methods named "test_XYZ" are called by the JUnit test running and executed.   In test_add, I'm basically just asserting that add does what it should do.  

You can read the JUnit documentation at http://junit.sourceforge.net/ to fill in anything I've missed out.
JUnit use for programmer to test their code. It is not for tester.
JUnit is just useful to test logic of your program.
Mayank SAssociate Director - Product EngineeringCommented:
Tutorial: http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/junit/junit.html

It is integrated with IDEs like Eclipse and Netbeans so you can directly use it.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now