JUnit 4.7 Rules, Dude!

Most popular software fades after awhile, but a few classics just keep dominating their markets. JUnit was the first unit-testing tool for Java. It faded for a bit and others, such as TestNG started to appear, but JUnit has come back strong. The latest release, 4.7, just went out the door with a cool new feature called Rules that will help us eliminate all kinds of special cases and test subclassing that make our tests less readable. Kent has a lot more to say about them, but to summarise they’re like test hooks on steroids. Want to log every test? Guarantee you close a database connection or a file in every test? Timeout every test? Use a Rule. Awesome!

At youDevise we will probably use it to mix and match test capabilties. Want a browser test that also has access to the database? No problem, just use the Browser and DatabaseAccess roles! I can see the possibilities opening up already.

Leave a Reply

Your email address will not be published. Required fields are marked *