JUnit and Other Beasts, Part 4

22 June 2012, by

Looking back

So far in this series of posts, we’ve covered JUnit’s basics, runners, and rules, we’ve unearthed the ideas behind theories, and seen how to put these ideas into practice.

In this final installment, we’ll have a look at what else theories might have to offer, and where to find out more.

.NET support

If you happen to be using .NET for your project, but you like what you see here, fear not! Theories, assumptions and data points all translate directly into NUnit. I haven’t tried this myself, but it looks essentially identical to the JUnit implementation, so all the information in these posts should still be relevant.

Automated exploration

As the papers mentioned in Part 2 note, the combination of theories and assumptions lends itself quite nicely to automation exploration of data points. Given a theory that indicates valid input values with assumptions (thereby restricting the possible input space) and which also makes assertions about the results of processing those inputs (thereby restricting the possible result space), the hope is that software could inspect the code and suggest ‘interesting’ data points – i.e. ones which satisfy the assumptions but fail the tests, highlighting either a bug in the production code or a test which could be refined. Indeed, the JUnit release notes mention that JUnit Factory can be used to search for potentially ‘interesting’ data points, rather like Pex in the .NET world. Sadly, it seems the JUnit Factory web presence no longer exists. Another piece of software, tpalus, seems to provide similar functionality, but seems to be quite young and in flux, so perhaps not quite ready for serious use, just yet.

Further reading

Given there’s very little documentation around for theories, most of the information on theories in these posts has been pieced by having a combination of experimentation and searching around blogs. Some of the posts that are useful are as follows:

That’s all, folks

Hopefully this series of posts has made you aware of just how powerful and flexible modern testing frameworks can be. If you ever find yourself banging your head against a JUnit brick wall, don’t give up in despair – chances are good that there is a solution out there, the trick is just tracking it down.

Happy testing!

Tags: , , ,

Categories: Technical


Leave a Reply

* Mandatory fields

2 + = seven

Submit Comment