pkg/unittest: shedding some cruft, getting some awesome
9:15am 7 Feb, 2014 These changes have not been released to the pub site yet.
tl;dr
- If you're testing code using Future, Stream, or anything async, you'll notice a lot fewer crashes and a lot more helpful stack traces.
- If you're subclassing Configuration, keep reading.
- If you're using APIs on TestCase, keep reading.
- If you're just using test, group, expect, etc. you're likely fine.
- Update pub dependencies on unittest to includes 0.10.0 to get the new hotness. (You might have something like
>=0.9.0 < 0.10.0, change it to>=0.9.0 <0.11.0)
- Each test is run in a separate
Zone. This ensures that any exceptions that occur is async operations are reported back to the source test case. - DEPRECATED
guardAsync,protectAsync0,protectAsync1, andprotectAsync2- Running each test in a
Zoneaddresses the need for these methods.
- Running each test in a
TestCase:- Removed properties:
setUp,tearDown,testFunction enabledis now get-only- Removed methods:
pass,fail,error
- Removed properties:
interactive_html_config.darthas been removed.runTests,tearDown,setUp,test,group,solo_test, andsolo_groupnow throw aStateErrorif called while tests are running.rerunTestshas been removed.
These changes cover three big areas:
- Remove unsupported APIs. The interactive test case runner hadn't been touched in a long time and it didn't support a number core test case features, like setUp and TearDown. The rerunTests function only existed to support the interactive runner and introduce a lot of weird state in unittest.
- Make TestCase immutable. Expect more changes here. TestCase should contain the logic to run the test. The result of the run should be in another object. We're getting there.
- Make testing async code easier. All tests are now run in a Zone. This means all any errors thrown by async operations are now funneled to the calling test case without requiring guardAsync or a protectAsyncN function (these are now deprecated).
Going forward, we're looking into more changes:
- Remove more state from TestCase.
enabled,isComplete,passed, andstartTimemay be removed from this class and exposed somewhere else. - I'm hoping to have a model where TestCase exposes
Future<TestResult> run([Configuration config])or similar. - More powerful ways to run unit tests, making it easy to run tests is parallel in zones, for example.
I'd like unittest to evolve to expose a very simple API that others can build on, with a layer of "easy" for those that just want to get something tested without a lot of ceremony.
Your thoughts and suggestions are welcome!
Happy hacking.
