Mark Derricutt's Disturbing Thoughts

New Inspections for the IntelliJ TestNG Plugin

posted Friday, 23 March 2007

The TestNG unit test framework provides a lot of features which make the testing of your applications so much easier than it would be with the likes of JUnit, one of these features is the ability to define dependencies on other methods/groups for your tests. These dependencies are defined through the use of the dependsOnMethods and dependsOnGroups attributes of TestNG's @Test, @BeforeXXX, and @AfterXXX annotations.

One annoying problem with these is the fact that the values are just strings, and as such are not caught by Java's strict typing, so a few hours hacking on the TestNG IDEA plugin and a few more intentions and quick fixes are starting to emerge:

I don't know why but I found I commonly enter a method name with the ()'s attached, so this is now trapped.

After removing the brackets, and deleting one too many characters we see that the method is now listed as being unknown - most excellent. And what about the group? Groups don't really have any baring or relation to the code base so we can't do any magic lookups to decide whats valid and whats not - so we do the next best thing:

For groups I'm keeping a list of "defined" groups in the projects .iws file along with the projects default parameters. A quick fix is provided which simply adds the group to the known list of approved group names (this list will be available for editing in the project settings).

As all of these items are inspections, you get to see them in your inspection reports as well:


I have in mind more inspections to add as well:

  • Group names with spaces, dots, or potentially bad characters
  • Group name checking in suite.xml files
  • Class name checking in suite.xml files
  • Method name checking in suite.xml files
  • ...any others people come up with?

Once I get done with more inspections, and more quick fixes where relevant, I want to take a look at adding completions of group, class, and method names as well (this is an API of IDEA I've not had a look at yet so I'm not sure how easy/hard it is).

Hopefully a new release of the plugin with these inspections will be coming out shortly, but these screen shots are just a short teaser of what I'm playing with - if anyone has any suggestions or more intentions shout out now.

Technorati : , , ,
Del.icio.us : , , ,

tags:        

links: digg this    del.icio.us    technorati    reddit