MXUnit 2.1 Released

Saturday, November 12, 2011

We’re pleased to announce the release of MXUnit version 2.1, comprising contributions from long-time MXUnit developers and new contributors alike.

This version includes:

Test Decorators

Without doubt the most significant feature in this release is “Test Decorators”, largely contributed by Mark Mandel. Decorators let you change MXUnit’s default behavior by writing a bit of your own code, without having to change MXUnit’s internals. We’ll be bringing you more documentation on this soon, but in the meantime, some problems this will solve are:

  • --Being selective in which tests get run on which platforms
  • --Controlling the sort order of tests
  • --Adding auto-rollback functionality to tests which commit data to databases
  • --Controlling which functions in a TestCase get ignored
  • --Enabling you to use custom attributes on tests, and respond to those attributes in your decorators
  • And so on

The mechanics are thus:

  1. Write a new component which extends mxunit.framework.TestDecorator
  2. Override any of the functions in the base TestDecorator to achieve the functionality you desire
  3. Add that decorator to your testcase, like so: <cfcomponent mxunit:decorators=”My.Custom.Decorator”…>
  4. Optionally, use custom function attributes and respond to them: <cfset var someAttribute = getAnnotation(methodName, "myCoolAttribute")/>

See MXUnit’s built-in decorators for examples and ideas.

Array, Query, and Structure Comparisons

Another significant change is how MXUnit compares arrays, queries, and structs in equality assertions. Up till now, these were done via turning those datatypes into strings and doing string comparisons.

With MXUnit 2.1, you’ll get a full comparison of these datatypes. When mismatches occur, you’ll be able to see the full set of mismatches in both the Eclipse plugin and when running tests via the browser. When running from the plugin, you can either use the Compare Dialog to see the differences, or use MXUnit’s “debug” output to view a structure which explains all the differences. They look thusly:

CompareDialog

And

DebugOutputForComparisonFailures

This is a first stab at deep comparisons, and we expect that as you use them, you’ll identify areas for improvement. We always welcome patches and pull requests. It goes without saying that accompanying tests are required.

 

Test Ordering

Thanks to Ryan Anklam for contributing a long-overdue feature. Until now, test ordering was unpredictable. Ryan’s contribution will order tests in the order in which ColdFusion’s getMetadata() reports them. While still not deterministic – getMetadata() will not order tests exactly in the order they appear in the TestCase – it’s a welcome improvement over the current behavior.

In addition, with TestDecorators, it’s easy to get alphabetical ordering if you wish, since MXUnit ships with an Alphabetical ordering test decorator. See this example test for how to use it.

Special thanks to Tim and John Farrar for the conversations inspiring the TestDecorator feature, and to all who contributed bug reports, patches, and feature code to this release.

 

--Marc

No comments: