Testing is one of the main phases in software engineering. It includes execution of different scenarios to deliver a bug free and well tested product that ensure high quality to customer.The testing is divided into the following 5 types .
1. Component testing: Component will be for example a set of tightly related classes. These classes are combined together to achieve a certain functionality.
2. System testing: Taking into the consideration overall functionality of the system. All the functions of the system are covered.
3. Acceptance testing: Check if the system achieves the customer functional requirement.
4. Load testing: Checking the system stability and how it will behave under high load circumstances.
5. Unit testing: Testing the software using validation methods .The unit is the smallest part of testing in the software.
Unit testing tools :
Junit ,
Cactus ,
Junitee ,
SOAPUIa. JUnit test framework JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.
JUnit is now the unofficial standard for unit testing Java-based applications. the common structure
Here is a code sample :
- Code:
package org.calc.test;
import static org.junit.Assert.*;
import junit.framework.TestCase;
import org.calc.Calculator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CalculatorTest1 extends TestCase
{
Calculator calc=null;
public void setUp() throws Exception
{
calc=new Calculator();
}
public void tearDown() throws Exception
{
calc=null;
}
public void testAdd()
{
long result=calc.add(3, 4);
assertEquals(7, result);
}
}
Assert methods : static void
assertEquals (boolean expected, boolean actual)
Asserts that two booleans are equal.
static void
assertFalse (boolean condition)
Asserts that a condition is false.
static void
assertNotNull (java.lang.Object object)
Asserts that an object isn't null.
static void
assertNotSame (java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object.
static void
assertNull (java.lang.Object object)
Asserts that an object is null.
static void
assertSame (java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object.
static void
assertTrue (boolean condition)
Asserts that a condition is true.
static void
fail (java.lang.String message)
Fails a test with the given message.
static void
failNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
private static void
failNotSame (java.lang.String message, java.lang.Object expected, java.lang.Object actual)
private static void
failNotEquals (java.lang.String message, java.lang.Object expected, java.lang.Object actual)
private static void
failSame (java.lang.String message)
(package private) static java.lang.String format (java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Test suite
A test suite is a composite of related tests that you can run during the same session. There are two convenient ways that JUnit runs test cases:
With the first way, you pass the test class to the TestSuite constructor by using this command:
TestSuite suite= new TestSuite(testAddJava.class) In this case, the TestRunner extracts all test methods that have a test prefix, and then executes each test case automatically.
The alternative way is add each test case by using the TestSuite.addTest method:
- Code:
TestSuite suite = new TestSuite(); suite.addTest(new AddJavaTest("testSimpleAddition"));
b. Cactus test FrameworkCactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters, ...) The intent of Cactus is to lower the cost of writing tests for server-side code. It uses JUnit and extends it.
c. JUnitEE test frameworkJUnitEE is a simple extension to JUnit which allows standard test cases to be run from within a J2EE application server. It is composed primarily of a servlet which outputs the test results as html
d. SoapUISOAPUI is a is a free and open source desktop application for inspecting, invoking and testing (functional and load) of web services over HTTP. It is mainly aimed at developers/testers providing and/or consuming web services (java, .NET, etc).