Agitator makes testing a breeze

 

Summary

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

Events

IBM Technology Conference & Expo 2012
May 23, 2012

Convention Centre B2 Room at 22nd Floor, Centara Grand @ Central World, 999/99 Rama I Road, Pathumwan, Bangkok 10330

Echelon 2012
June 11 and 12, 2012

University Cultural Centre, National University of Singapore

Startup Asia Jakarta 2012
June 7 and 8, 2012

12th Floor, Annex Building, Wisma Nusantara Complex, Jl. M.H. Thamrin No. 59 Jakarta 10350, Indonesia

MMA Forum Singapore
April 23-25, 2012

Grand Hyatt 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

Malaysian organizations are apathetic about information security and fail to realize they are potentially under... http://t.co/XeuvbXrs

Big data acquisitions pave way to fast, effective innovation - ZDNet Asia News http://t.co/vDZpl0lu

"Big data acquisitions pave way to fast, effective innovation" including @Vivisimo_Inc (client) in @ZDnetAsia http://t.co/yNSdPqbb

Homegrown smartphone OSes gaining favor in China: 59 Jakarta 10350, Indonesia Locally-made mobile operating syst... http://t.co/BruP98Es

RT @MDMGeek: Big data acquisitions pave way to fast, effective innovation - ZDNet Asia http://t.co/ky8YgPAn #Bigdata #analytics via @ciropuglisi

Integration, focused investments to propel Windows Phone http://t.co/6JkDa9sB

RT @AsianFashionLaw: Malaysia offers some manufacturing benefits over China http://t.co/bMquIFiX

Acquisitions in the Big Data market increasingly important to enterprises… http://t.co/Br4BkXyZ

Experience trumps content in apps monetization http://t.co/iaCY5ebX

Malaysia offers some manufacturing benefits over China http://t.co/bMquIFiX

RT @MDMGeek: Big data acquisitions pave way to fast, effective innovation - ZDNet Asia http://t.co/ky8YgPAn #Bigdata #analytics via @ciropuglisi

Thats it.Im digging up an old bus plan i wrote around acquisition of #bigdata talent. http://t.co/gpkha5A1 Any investors want2 read/discuss?

Integration, focused investments to propel Windows Phone: By Kevin Kwang , ZDNet Asia on May 23, 2012 (2 mins ag... http://t.co/aaa0Cb73

Homegrown smartphone OSes gaining favor in China http://t.co/lOBVp1T6

Homegrown smartphone OSes gaining favor in China: 59 Jakarta 10350, Indonesia Locally-made mobile operating syst... http://t.co/gHypbdIY

So much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...

1 day ago by y15822137359 on 5 SaaS adoption speed bumps to avoid

I reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...

2 days ago by wykoong on Gartner: Mobile CRM gives better ROI than social

This video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...

3 days ago by TradeBrother on A quick fill handle trick for Microsoft Excel

waiting...

5 days ago by eapete on What should count in a company's market value?

Boy, you've opened a can of worms now.

Wait for the rants & raves.

5 days ago by eapete on What should count in a company's market value?

I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...

5 days ago by wykoong on Drop the egos, copy ideas, then innovate