Posted on 2006-05-20
Last Modified: 2010-03-31
what are the steps involved in junit to check each modules

could you explain with simple
Question by:stmani2005
    LVL 4

    Accepted Solution

    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 to fill in anything I've missed out.
    LVL 6

    Assisted Solution

    JUnit use for programmer to test their code. It is not for tester.
    JUnit is just useful to test logic of your program.
    LVL 30

    Assisted Solution


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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now