Mark Derricutt's Disturbing Thoughts

My Top Tags

                                       

My Jaiku

The Taste of the Day

Thursday, 24 July 2008 10:28 A GMT+12

War of Ages – The Deception of Strongholds

Wednesday, 23 July 2008 5:41 P GMT+12

"L" is not a code smell

Wednesday, 23 July 2008 8:54 A GMT+12

Meshuggah – Sum

Tuesday, 22 July 2008 4:37 P GMT+12

Dates: Relative or Absolute?

Tuesday, 22 July 2008 8:19 A GMT+12

HTTP errors - a set on Flickr

Monday, 21 July 2008 5:37 P GMT+12

Daylight Dies – Last Alone

Monday, 21 July 2008 3:59 P GMT+12

How I Got Started in Software Development

Sunday, 20 July 2008 6:06 P GMT+12

Soilent Green – In The Same Breath

Sunday, 20 July 2008 3:40 P GMT+12

Search Box

 

Writing fine grained test requirements with expressions

posted Saturday, 20 October 2007

The other day a discussion arose on the TestNG users list about enhancing TestNG's dependency and group capabilities with more fine grained control of when tests get skipped, an idea I came up with which doesn't require any patches to TestNG was to make use of TestNG's Annotation Transformers coupled with an expression language such as mvel.

A bit of hacking tonight yields a working requirements transformer:

@Test
@Requires({"sys['user.name'] == 'amrk'"})
public void someTestThatOnlyRunsForMyUser() { ... }

When TestNG is invokved with the RequirementsTransformer each test that has an associated @Requires annotation is first vetted for validity using the mvel expression language. Currently the expressions context contains the current system properties in the variable 'sys' but the suites properties could be easily pulled in as well.

When an expression fails, the test is set to depend on a group with a name matching the expression:

java.lang.Throwable: Method test.TestWithRequirements.labla() depends on nonexistent
  group "sys['user.name'] != 'amrk'"

(currently this is the only way I can see to have an annotation transformer trigger a test skip).

This could be an easy to automatically filter tests from running on different hosts, environments, users - or it could just be overkill. Either way, the codes available for download for anyone to play with - I might throw this up into google-code as well thou.

Technorati Tags: , , ,

tags:        

links: digg this    del.icio.us    technorati    reddit