See which of your colleagues or former colleagues are already on Testing Link: Check out the Contact Finder
News »Browse Articles » JUnit Testing
0
Vote Vote

JUnit Testing

Views 1 Views    Comments 0 Comments    Share Share    Posted 07-07-2009  
JUnit is a Java framework for performing unit tests on code. By testing code after every change, programmers can be reassured that changing a small amount of code does not break the larger system.
Without automated testing tools like JUnit, retesting can be a tedious and inaccurate process. By allowing the testing process to occur frequently and automatically, you can keep software coding errors at a minimum.

Creating the test cases, however, can be a difficult process requiring knowledge of exactly what the code does and how it should perform. You must carefully create the unit tests performed by JUnit to ensure that the tests rigorously check the code just as it would run in the real world. In this article, we first look at how to create unit tests and then at how to put together test suites.

Introduction

JUnit is a framework for implementing testing in Java.

It provides a simple way to explicitly test specific areas of a Java program, it is extensible and can be employed to test a hierarchy of program code either singularly or as multiple units.

Why use a testing framework? Using a testing framework is beneficial because it forces you to explicitly declare the expected results of specific program execution routes. When debugging it is possible to write a test which expresses the result you are trying to achieve and then debug until the test comes out positive. By having a set of tests that test all the core components of the project it is possible to modify specific areas of the project and immediately see the effect the modifications have on the other areas by the results of the test, hence, side-effects can be quickly realized.

JUnit promotes the idea of first testing then coding, in that it is possible to setup test data for a unit which defines what the expected output is and then code until the tests pass. It is believed by some that this practice of "test a little, code a little, test a little, code a little..." increases programmer productivity and stability of program code whilst reducing programmer stress and the time spent debugging.

What is JUnit?

JUnit is a simple open source Java testing framework used to write and run repeatable automated tests.

It is an instance of the xUnit architecture for unit testing framework. Eclipse supports creating test cases and running test suites, so it is easy to use for your Java applications.

JUnit features include:

* Assertions for testing expected results

* Test fixtures for sharing common test data

* Test suites for easily organizing and running tests

* Graphical and textual test runners

Installation

It is assumed that you know how to setup environment variables and install software on your operating system, for a comprehensive guide to doing so for Windows see Configuring A Windows Working Environment, for Unix see Configuring A Unix Working Environment Follow these instructions to install JUnit:

1. Download the latest version of JUnit from http://download.sourceforge.net/junit/

2. Uncompress the zip to a directory of your choice.

3. Add /path/to/whereyouextractedjunit/junit/junit.jar to your Java CLASSPATH environment variable. ...

Source:
http://www.onestoptesting.com/junit-testing/
0
Vote  Vote
Enter your comment:
No Comments For This News

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Testing community to read.

Most Popular News

Most Recent User Submitted News