Agitator makes testing a breeze

 

Summary

Latest version of Agitar's testing tool aims to make test generation automatic.

Events

Asian Financial Services Congress 2012
23 - 24 Feb 2012

Marina Bay Sands, Singapore

The amount of effort involved in writing unit tests puts most people off doing it, especially for older code. The latest version of Agitar's automatic testing tool aims to make test generation automatic.

The hardest thing about testing is writing the tests in the first place; once you have tests, a whole panoply of tools can be applied to manage and report on those tests. But writing the tests, and writing them so they actually cover everything can be laborious and tedious, and tedium leads to errors. Enter Agitar's Agitator, a technique and a tool set, which sets out to ease test development and encourage test-first development.

Agitation, as a technique, is akin to handing your code to an assistant programmer who knows nothing of the context of the code and asking them to document everything that code actually does. They set about testing it by constructing code which feeds a range of possible values into each of the methods in the code and observing how variables change between the start and end of the method's code. They return to you with a list of these observations from which you select which ones you want to be tested for. In the future, when you change the code, you can ask the assistant to test the code according to those selected observations. Of course to do this, consistently, for every line of code is almost impossible and that's where Agitator comes in, automating the entire process and acting as a virtual assistant.

Agitator integrates into the Eclipse IDE (Integrated Development Environment) as a plug-in or can be run from other IDEs, which launches Eclipse anyway. There are also command line tools for running on a build server to integrate with your development workflow. Within Eclipse, there's a new Agitation perspective which compresses the agitation process into pressing F9 to agitate a project. After agitation, the observations are displayed, ready for selection to become assertions.

The simplicity of code agitation disguises the complexity of scaling that technique up to typical codebases. Agitator manages to effectively hide that complexity with a simple interface and a lot of intelligence about how to handle generating tests without user intervention, without locking you out of being able to go in and change them. For example, creating that raw data to feed into the testing process is managed by factories; initially default factories are created so, for a native int, you get a factory which generates a random range of int values. Factories can, of course, generate class instances for testing too, including the automatic generation of mock objects based on existing types, using nested factories to generate parameter values for those mock objects. If you want to override the factory being used or test with a different generator, you can assign a new factory, varying the ranges or drawing them from an iterator or randomly from an array, generating random instances of a class. Specialised factories, for example generating servlet sessions, requests and responses, fill out the armoury.

Observations are expressed in Agitator's notation, which looks like a boolean expression, but includes functions like @PRE(x) which would be the value of 'x' before the test was executed and @RETURN which is the value the tested method returned. Agitator doesn't have to generate these observations; you can enter your own observation expressions, which is key to test first development. You can write a 'shell' method, manually enter the observations you want to be true and then agitate, at which point the assertions will fail and continue to do so till you write correct code to pass those tests. When an assertion fails, you can dig through to a snapshot of the test which reveals each iteration of the agitation where you can browse what values were fed in. Coverage is all important when testing and Agitator puts your coverage information right inside the editor, adding in the left hand side coverage tags which show how well each line is test covered, and flagging tested paths in green and untested paths in red. This is the signature of Agitator, putting testing and coverage results immediately in front of the developer, flagging untested or weakly tested code and reducing the effort in creating tests to remedy those omissions.

Beyond the core agitation technique, Agitator builds out with Experts, which allow you to cut across a project with a set of default rules of your own creation. Say you have a convention that all methods that begin with "do" should return an integer within a range, you can add an expert which matches the method name using a regular expression, and then create an assertion to enforce that rule. Whenever Agitator matches a rule, it flags it up in the Experts panel and editor and asks if you want to apply the associated observations. Agitator comes with some ready constructed Experts for J2EE (Java 2 Enterprise Edition). and Struts, which is useful, but the feature doesn't feel as tightly integrated as the core functionality and the Experts UI feels laborious. That said, Experts has a lot of potential for embedding cross team coding discipline.

Agitator is a powerful tool, pulling together the development and reporting of tests deep into the coding cycle. What Agitator isn't is a magic bullet; throw it at an existing legacy project and you still, quite reasonably, have to figure out which observations should become assertions, and even then you have only the skeleton of default tests. It is best introduced to a legacy project in an organic fashion where you can focus on getting high coverage in small areas. For new projects, Agitator's positive encouragement of test first development could well make it an essential tool. The only possible inhibitor is the cost which starts at about US$3,438 per user, with discounts as the user count goes up over ten; you really need to be sold on agitation, and there's no "Agitator-Lite" to get you hooked, but trust us, once you've agitated your code, you won't want to go back to hand crafting all your testing.

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

ZDNet Asia Live

Microbloggers in Beijing must authenticate real names before 16th March or will have their access limited to browsing. http://t.co/tB30exzy

DailySync 2.2 http://t.co/CSogJW6P

RT @BeyondTrust: Breached security vendors' response should focus on customers http://t.co/PxDjTjEJ #infosec #databreach #security

Judge: Chinese engineer didn't spy on US: By Ellyne Phneah , ZDNet Asia on February 9, 2012 (11 hours ago) US ju... http://t.co/7Cw5G6Be

New standards make using carrier Wi-Fi super easy: ... ago) A set of new standards being developed will soon mak... http://t.co/Xvnumaxx

First 'biological computer' created, can read DNA. http://t.co/7dny07vS

Amazon breaks into India online retail market http://t.co/MUR5i5NU

Singapour : 95% des foyers et societes seront equipés en fibre optique mi-2012 http://t.co/zPLb1erU

RT @HostingInAsia: Singapour : 95% des foyers et societes seront equipés en fibre optique mi-2012 http://t.co/zPLb1erU

Gr8 article via @ZDNet on user's role in securing their videoconferencing estates: http://t.co/0KuypBEN

RT @ArkadinAPAC: Home telepresence demand to grow despite hiccups http://t.co/1yz8tSdK

New Wi-Fi standard won't replace Ethernet http://t.co/NgALh39J via @zdnetasia

APP NEWS--RIM says app interest actually really high
http://t.co/iNIMbdYW

EU News: New standards make using carrier Wi-Fi super easy: Joining a carrier Wi-Fi hot spot on your... http://t.co/trMYbugj #smartphone

Home telepresence demand to grow despite hiccups http://t.co/1yz8tSdK

Nice research and pardon If there are some major issues which make cloud security trembling & risky.. 1. Abuse and Nefarious Use of Clo...

12 hours ago by evabrian on Cloud, mobility to drive security market

Nice research and pardon If there are some major issues which make cloud security trembling & risky.. 1. Abuse and Nefarious Use of Clo...

12 hours ago by evabrian on Cloud to drive industry, security concerns remain