JUnit - Overview

Advertisements


Testing is the process of checking the functionality of the application whether it is working as per requirements and to ensure that at developer level, unit testing comes into picture. Unit testing is the testing of single entity (class or method). Unit testing is very essential to every software company to give a quality product to their customers.

Unit testing can be done in two ways

Manual testingAutomated testing

Executing the test cases manually without any tool support is known as manual testing.

  • Time consuming and tedious: Since test cases are executed by human resources so it is very slow and tedious.

  • Huge investment in human resources: As test cases need to be executed manually so more testers are required in manual testing.

  • Less reliable: Manual testing is less reliable as tests may not be performed with precision each time because of human errors.

  • Non-programmable: No programming can be done to write sophisticated tests which fetch hidden information.

Taking tool support and executing the test cases by using automation tool is known as automation testing.

  • Fast Automation runs test cases significantly faster than human resources.

  • Less investment in human resources:Test cases are executed by using automation tool so less tester are required in automation testing.

  • More reliable: Automation tests perform precisely same operation each time they are run.

  • Programmable: Testers can program sophisticated tests to bring out hidden information.

What is JUnit ?

JUnit is a unit testing framework for the Java Programming Language. It is important in the test driven development, and is one of a family of unit testing frameworks collectively known as xUnit.

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

Features

  • JUnit is an open source framework which is used for writing & running tests.

  • Provides Annotation to identify the test methods.

  • Provides Assertions for testing expected results.

  • Provides Test runners for running tests.

  • JUnit tests allow you to write code faster which increasing quality

  • JUnit is elegantly simple. It is less complex & takes less time.

  • JUnit tests can be run automatically and they check their own results and provide immediate feedback. There's no need to manually comb through a report of test results.

  • JUnit tests can be organized into test suites containing test cases and even other test suites.

  • Junit shows test progress in a bar that is green if test is going fine and it turns red when a test fails.

What is a Unit Test Case ?

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

A formal written unit test case is characterized by a known input and by 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 postcondition.

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.



Advertisements
Advertisements