JUnit: A Little Beyond @Test, @Before, @After
A minor annoyance is that JUnit doesn't provide a readable output when running parameterized tests. In a report they are displayed as:
This happens everywhere, both with JUnit run from a shell and with an IDE such as NetBeans. It isn't helpful to see that testImage failed, as you have to manually look up the source code, or look at the test log files, to find out which test file triggered the failure.
Inspecting JUnit sources, I've found that there are two specific methods in Parameterized that returns the display name of the test. So I copied the source into my own MyParameterized that has been patched as follows:
public class MyParameterized extends Suite
private class TestClassRunnerForParameters extends BlockJUnit4ClassRunner
protected String getName()
return String.format("[%s]", Arrays.toString(fParameterList.get(fParameterSetNumber)));
protected String testName (final FrameworkMethod method)
return String.format("%s[%s]", method.getName(), Arrays.toString(fParameterList.get(fParameterSetNumber)));
In this way ExpectedResults.toString() is used as the test display name and I see speaking reports even in my NetBeans IDE:
I've not submitted a patch to JUnit yet since I'm studing this stuff to enhance it even more; for instance, to run tests in parallel. I've just rented a 8-core server for my Continuous Integration and I hope to make my tests run faster at least of a 4x/6x factor. But that's a topic for another article.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)