Unit testing is a practice that developers use to test their code modules in isolation to make sure that each module does what it's supposed to. JUnit is an Open Source frame¬work which helps in unit testing, specifically coded on the Java platform. Developers just have to determine the test cases and create JUnit tests for their code modules.
In a typical setup, developers don't prefer this added burden of unit-testing on their shoulders, as they feel that this should be done by the testing division. They often overlook the benefits of doing unit-testing at developmental stage, be¬cause it requires too much work. This used to make it extremely difficult to convince developers to do unit-testing at their end.
Now, there's a tool that has been in¬troduced by Agitar, called Agitar One, which creates JUnit tests automatically for code modules and also prepares th<: test cases for them. This significantly reduces the time required for unit testing, enabling an organization to convince its developers to take up the job.
AgitarOne steps in
As we mentioned,AgitarOne is a unit¬testing software for enterprises who are engaged in Java-based development. Pro¬ject managers can use it at developmental stage so that their developers can implement unit-testing.
It is a server-based model and can ex¬ecute through the code modules to test how the given code will perform under normal as well as exceptional conditions. AgitarOne relieves the developer by gen¬erating several test-cases for code mod¬ules, even for those code patterns which developers find tedious to create the JU¬nit tests for and normally skip when do¬ing the task, manually.
Once a module is put under test creation,AgitarOne reads through the code, creates the test on-the-fly and generates the report based on the results, observing which lines of code were executed and which lines were excluded. Any anomalies in the code can easily be caught from these reports.
The test values that AgitarOne uses are based on random generation of values for variables and functions. When any test fails, AgitarOne reports the sequence of functions and values passed to them so that a developer may trace through the code to evaluate the reason why a particular code couldn't handle the value, as per expecta¬tion. Like this, quality can be ensured for a code module right from the development process.
Installation and setup
AgitarOne is based on Eclipse IDE and it comes packaged with it. Alternatively, it can also be installed separately as a plug-in to an existing Eclipse IDE. In the packaged version, Tomcat server is au¬tomatically configured for AgitarOne and the client machines can access AgitarOne's Dashboard remotely.
Once the server and clients have been configured, it's just a few clicks of process for developers to automate the unit-testing process for their code modules.
The developer has to select his project or a class- file and through Agitar's drop¬down menu he can select to create tests, agitate the code, run the code-rule or genAgitarOne in action
The software agitates on a given code module to check for what that code was intended to do and what it actually does. Agitation can be described as a process of creating multiple instances of classes, and calling all methods of those classes with a wide array of input data and ob¬serving the results thus generated.
This input data can be randomly generated by AgitarOne or can be manually passed by the developer through fac¬tories (user-defined subclasses). Then it's up to the developer to check which observation forwarded by AgitarOne is not matching the desired behavior and the reason for it.
For experiencing this agitation process, let us take a sample project pro¬vided with AgitarOne. We will try agitating Product class and see the observations presented by AgitarOne, so that we are able to assert on a few of them to validate code behavior.
In the Product class, we have valida¬tion checks for name and price fields. Where name can't be more than 20 char¬acters and price field can have a value between 0 and 1000.
To start the agitation process on Product class, select Product.java and click on Agitate toolbar button or press Ctrl+F9. Now, in the editor window for Product.java, we can see in the Code Coverage style the number of times a particular line of code has been executed. The red indicates that some lines have not been touched by control flow. In AgitarOne Server view, status and cover¬age (indicates what percent of the code lines have been executed) is displayed.
The Observations view indicates where the problems may be lying with the code module, in our case the Product class. Notice the following observation As we had defined that a name can't be more than 20 characters long, in this observation we can see that AgitarOne was able to pass more than 20 characters long values to the field 'name'. This means a validation for that is not being executed or is being ignored by the pro¬gram control during execution.
Now the developer can directly pre¬sume that the validateNameO method of the code is not being called when set¬NameO method passes the value for name field. By changing the setName method to look as following code snippet we can eliminate the error.
public void setName(String name) throws IllegalArgumentException { validateName(name); this. name = name;
When we again agitate the Product class, under the Observations view, we see a modified observation listed. The observation for getNameO has also been modified.
Similarly, the developer can make as¬sessment for other observations. He can assert an observation to hold true for a situation and can again run agitation to check the code behavior. This way a developer, who is well familiar with his code, can at developmental stage only eliminate possible redundant errors, by using AgitarOne.
The functionality of Dashboard is an added advantage, both for a developer and the project leader. As in Dashboard, the whole coverage percentage of the projects' classes, their progress and the highest risk classes can be viewed.
Conclusion
With the automation of unit-testing, a developer with the help of AgitarOne can implement quality code creation, right from developmental stage onwards. Hence, enterprises will benefit with reduced time of testing and developers will be able to debug their code and improve productivity, significantly.




Reply With Quote
Bookmarks