Table of Contents
What is automated unit testing and how does it work
Unit testing is a software development technique that involves a computer program testing individual units of code without executing the whole program. This allows developers to test whether an isolated unit of code behaves according to design by running specific tests. Unit testing is an important step in the software development process, especially for more complex programs.[1] Automated unit testing is a software development technique that involves using a computer program to test individual units of code without executing the whole program. This can allow developers to test whether an isolated unit of code behaves according to design by running specific tests. Unit testing is an important step in the software development process, especially for more complex programs.[2]
Unit testing allows developers and testers to find defects in their programs before they go into production. This can result in improved efficiency and quality, at a lower cost and without needing to release prematurely.[2]
Unit testing is one of the most important phases in software development. The following factors enable to achieve high quality code:
Typical unit testing methods follow the step-wise approach below:

Advantages of automated unit testing
Unit testing allows developers to detect problems as soon as possible, cheaply and safely. The lack of failures during the unit test phase means that there will be no bugs in the system that cannot be found by automated unit testing. Thus it saves time; the developer’s time is back in the ‘safety’ phase, where he can concentrate on fixing bugs rather than finding them.[2] However, It can also identify possible flaws in components that have yet to be developed. This means that the developer of a unit can test components before they have been developed, preventing common defects at the coding stage. This can reduce costs by reducing the time spent on fixing bugs in completed products. [1]

Types of tests that can be automated
Unit testing can be automated in various ways. For example, if the unit being tested is an object, one can write a test that uses a tool that simulates user input and calls methods on the object to exercise its public interface. Alternatively, for every class in the system, one can create test objects of every other class and simulate the interactions of all objects. Then input data can be supplied to the program and its output can be checked against the expected results. The unit testing framework may also have a debugger with which to automatically detect logic errors, such as infeasible paths in a program.[3] While there are many kinds of unit tests, they generally fall into the following categories:
System-level tests, or integration tests, simulate end-user behavior of an individual unit by using one or more units in isolation. These are typically slower but can test non-local program behavior and can test a complete stack. If multiple units fail at the same time this could be a sign that they fail in concert. They generally use black box testing methods.
White box tests take as input a set of inputs and expected results, and check whether the actual output matches the expected output. White box techniques can test internal program decision making and the logic within a unit. They may be used prior to or instead of black box testing.

How to get started with automated unit testing
The ideal way to get started is with a quality unit test framework that is used for all of your projects. In the following example, we will use the JUnit framework to illustrate this point. The JUnit framework is a free unit testing framework that is part of the Java Development Kit (JDK). Once you install the JDK, it will include JUnit and all of its dependencies.
This article is specifically targeted toward those who are new to unit testing and who are looking for a free unit testing framework. If you’re already a seasoned professional, you might want to check out one of the more advanced unit testing frameworks like [TDD] or [Mockito] .
In this document, we will cover:
What to test
How to write a simple test case for a JUnit test method: “Write a JUnit test method” and “Load Mock Objects into the Unit Test Method”.
Other FAQs related to unit testing
Mock objects and JUnit: “How to test a method with a mock object” “how do I create a mock object?”.
What does this article NOT cover? Mocking, why would you need it? How do I use mocking in my unit tests?, etc…

Tools and frameworks that are available for automated unit testing
JUnit is a well-known, powerful, and freely available testing framework that has been used for unit testing since it was first developed. It is open source, developed by Kent Beck and Erich Gamma. JUnit provides a simple and extensible API for writing repeatable tests. Tests are organized into test classes that contain test methods. A test method may contain a set of assertions that can be easily checked, such as the number of words in a file. These tests can be used as part of a suite of tests that are run over and over again at different points in the development process (such as each time you check in code). JUnit provides facilities for both integrating with the IDE so that results are written to the editor, and for running the tests on multiple platforms.
JUnit + annotations ? test methods annotated by @Test attribute: static { System.out.println(“JUnit + annotations !”) }
The Eclipse JDT Team’s [[http://jdt.java.net/jdt-core/about|JDT Core Library]] provides the [[https://wiki.eclipse.org/Junit|Java unit testing framework]]. JUnit is licensed under the terms of the GPL while the Eclipse unit testing framework is licensed under EPL 2.0, which ensures that it will always be open source (and must be open source in order to be used by Eclipse projects).
“JUnit + annotations !” : “JUnit with JDT Core Library and annotation support”
The use of JUnit for unit testing is covered in the [[http://www.eclipse.org/articles/Article-TestingFaq.html|Eclipse Testing FAQ]].
