How to Replace Rules in JUnit 5

On April 6, 2016, Posted by , In JUnit, By ,,,, , With 11 Comments

The recently published JUnit 5 (aka JUnit Lambda) alpha release caught my interest, and while skimming through the documentation I noticed that rules are gone – as well as runners and class rules. According to the user guide, these partially competing concepts have been replaced by a single consistent extension…

A JUnit Rule to Run a Test in Its Own Thread

On July 21, 2014, Posted by , In JUnit, By ,,, , With 2 Comments

In JUnit it could be occasionally helpful to run a test in its own thread. In particular when writing integration tests that interact with encapsulated ThreadLocals or the like this could come in handy. A separate thread would implicitly ensure that the thread related reference of the threadlocal is uninitialized…

A JUnit Rule to Ease SWT Test Setup

On February 25, 2014, Posted by , In Eclipse,JUnit, By ,,,,, , With Comments Off on A JUnit Rule to Ease SWT Test Setup

Rüdiger and I have written a lot of SWT test cases for our current RCP project lately. Most of the time we can execute them as plain JUnit tests. Still they also have to run in a RCP integration environment. Long story short we wrote a DisplayHelper fixture to reduce…

A JUnit Rule to Conditionally Ignore Tests

On November 18, 2013, Posted by , In JUnit, By ,, , With 24 Comments

I always believed that using @Ignore to deactivate tests is a bad idea. Except, maybe as one way to put tests that fail intermittently into quarantine to attend to them later (as Martin Fowler describes it here). This bears the danger that the test suite decays as more and more…

Running JUnit Tests Repeatedly Without Loops

On April 10, 2013, Posted by , In JUnit, By ,,, , With 26 Comments

Recently I came across a problem where I had to write tests for a method that calculates randomly distributed values within a certain range of possibilities 1. More precisely if you assume a signature that looks like interface RandomRangeValueCalculator { long calculateRangeValue( long center, long radius ); } a test…

JUnit Rules

On September 24, 2012, Posted by , In JUnit, By ,,, , With 20 Comments

The first time I stumbled over a JUnit @Rule annotation I was a bit irritated of the concept. Having a public field in a test case seemed somewhat odd and so I was reluctant to use it regularly. But after a while I got used to that and it turned…