• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • 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.
Nguyen Huu PhuocSenior ManagerCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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