Home Register Members List Search Today's Posts Mark Forums Read

Go Back   TechFuels Forum > Software > Applications

Reply
 
LinkBack Thread Tools
techno23
Senior Member
 

techno23 is offline  
Old 02-07-2008, 12:00 PM
  #1 (permalink)
Efficient Unit - testing in Java

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.

Name:  9849.jpg
Views: 134
Size:  26.2 KB

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparative testing of chipsets for Intel processors techno23 Motherboards & Memory 0 02-07-2008 09:07 AM
Sun Java SE Runtime Environment 6.0 Update 4 cybercoder666 Download Tools and Softwares 0 01-28-2008 05:59 PM
Testing Hardware, Memmory, CPU, Hard Disk in a Laptop? dasilvaf2003 Download Tools and Softwares 1 01-28-2008 10:00 AM
Testing video techfuels Test Forum 0 01-06-2008 04:06 AM


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0
Copyright Techfuels -->
SEO by SubmitEdge


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151