Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


jDefend: One Configuration File for All Your Test Scenarios

How would you like to have a test driver that you don't need to recompile every time input parameters change?


WEBINAR: On-demand Event

Unleash Your DevOps Strategy by Synchronizing Application and Database Changes REGISTER >

very developer, at some point, has implemented a test driver to test his or her code. The alternative is writing a custom test driver for each test scenario. The custom driver would have to read the input data, parse it, turn it into objects, and then use those objects for each test scenario. How would you like to have a test driver that you don't need to recompile every time input parameters change?

With the open source jDefend test driver suite, you can configure all the input parameters and pass them to your test driver using a single XML-based configuration file. jDefend's parser class parses the configuration file and prepares all the test drivers listed for execution. It then executes each test driver—even on a different thread—for faster execution of the test scenarios. (Figure 1 shows the various components of the jDefend suite.)

Figure 1. jDefend Components: The jDefend suite is made up of various components.
In this article, I'll demonstrate how the jDefend test suite can make your Java code testing quicker and simpler, and I'll discuss how it also can simplify security testing.

jDefend in Action
To better understand jDefend's functionality, follow the test procedure for a simple class. Begin with a Java object called Student.

Listing 1: Student.java
package example; public class Student { private String name; private Address addr; public void setName(String n) { System.out.println("setName called"); name = n; } public String getName() { return name; } public void addressIs(Address a) { addr = a; } }

Next, load a class called StudentManager, which has three operations: add, remove, and find Student.

Listing 2: StudentManager.java
package example; import java.util.Vector; public class StudentManager { Vector students = new Vector(); public void add(Student s) { System.out.println("Entering StudentManager::add(Student s) "); students.add(s); } public void remove(Student s) { System.out.println("Entering StudentManager::remove(Student s) "); students.remove(s); } public Student findStudent(String name) { System.out.println("Entering StudentManager::findStudent(String name) "); Student stud = null; for(int i=0; i<students.size(); i++) { stud = (Student)students.get(i); String sname = stud.getName(); if (sname != null) { if (sname.equals(name)) { break; } } } return stud; } }

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date