JUnit

Testing is the process of checking the functionality of an application to ensure it runs as per requirements. JUnit is a java library for unit testing, which comes into picture at the developers’ level; it is the testing of single entity (class or method) and can be done in two ways − manual testing and automated testing.

JUnit promotes the idea of “first testing then coding”, which emphasizes on setting up the test data for a piece of code that can be tested first and then implemented. This approach is like “test a little, code a little, test a little, code a little.” It increases the productivity of the programmer and the stability of program code, which in turn reduces the stress on the programmer and the time spent on debugging.

A Unit Test Case is a part of code, which ensures that another part of code (method) works as expected. To achieve the desired results quickly, a test framework is required and JUnit is perfect for that.

A formal written unit test case is characterized by a known input and an expected output, which is worked out before the test is executed. The known input should test a precondition and the expected output should test a post-condition.

There must be at least two unit test cases for each requirement − one positive test and one negative test. If a requirement has sub-requirements, each sub-requirement must have at least two test cases as positive and negative.

RESOURCES:

TutorialsPoint