One request that has come up frequently from users of the ColdFusion Koans was to have the ability to see the test results in order. This weekend I created a new test decorator that will allow users to do just that, set the order of the test results via annotation. Thinking it would be useful for others I opened a pull request on the MXUnit project and it was merged into the master branch on GitHub and added to the new 2.1.1 release.
In order to use the new decorator you must have MXUnit 2.1.1 or newer. One way to check if you have the required decorator is to look in the mxunit/framework/decorators directory for the file OrderdTestDecorator.cfc.
In order to set the order of your tests two things have to happen. The first is to add the custom decorator to you test component.
In a script based component the decorator is added like so:
In a tag based component you can add the decorator like this:
Once you have the annotation added to your test, you can start ordering them by adding the @order annotation to each test like so:
In a script based component the annotation looks like this:
In a tag based component it looks like this:
That's it, now your tests will run in the order you specified.
Nice addition Ryan.
ReplyDeleteI am getting an error when adding this and trying to refresh the list of test in the Eclipse plugin.
ReplyDeleteThe error is saying that it cannot find the component named mxunit.utils.BubbleSort. I tried re-downloading 2.1.1 from mxunit.org and there does not appear to be a 'utils' folder in the code anywhere - though I do see it on GitHub.
Just grabbed the latest from GitHub and got rid of the error.
ReplyDeleteQuestion for you, is this only for running tests in a browser or also in the Eclipse Plugin?
I tried this in both and neither worked as expected. The Eclipse plugin still ran them in alphabetical order. The .cfm page I set up to run test in browser ran the first 2 of 4 tests in the specified order, but the last 2 were inverted.
I know this will be hard for some to believe, but I had a typo in my file - causing the order of the last 2 items to be inverted.
ReplyDeleteAlso, I had forgotten that while testing something else, I had checked the 'Order methods alphabetically' checkbox in the Eclipse preferences panel for MXUnit.
So,all is good now, and working as expected.
This is awesome!
Dammit Scott I just wrote a nice long response and now its irrelevant :-). Thanks for testing this out though. Please let me know if you run into any other issues.
ReplyDeleteI'm also still waiting for your contribution to the Koans :-). Do it before the end of Feb and I'm giving away a copy of the ORM book to a contributor.
Sweet! I've often wanted to order my tests, but never knew if it was possible. I'll start using this right after upgrading to the proper MXUnit version. Thank you!
ReplyDelete