We put in a JUnit hack into our latest project that allows us to produce more readable test names.
@Override public String getName() {
return getClass().getSimpleName().replaceAll("Test$", "")
+ super.getName().substring(4).replaceAll("([A-Z])", " $1").toLowerCase();
}
Turning testTellsMeHowMuchInterestIEarnInAYear()
from the BankManagerTest
into Bank Manager tells me how much interest i earn in a year.
.
Note the disclaimer: Tests in IntelliJ are no longer clickable afterwards but the stack traces still are
Get the TestDox plugin for IntelliJ – it lets you view all your test names as sentence, switch between test and code, and create test names as a sentence. It’s best feature is being in code, hitting Alt-Shift-Q, and TestDox extracts the test names for the code and displays a little summary window shouwing you the expected behaviour of the code. It’s been an absolute godsend…
Hmmm… I was going to mention TestDox to.
Oh, and if you create a setName(String) method for the TestCase that know how to turn the name back into the canonical form (passing it to super.setName()), you’d be able to click on it in IntelliJ again. (You _may_ need to create a String constructor too, but I doubt it)
I have been introduced to TestDox before, but this is quite useful for reading test reports when they fail on your build server. I do like the plugin though. We may want to create the setName(String) method as Robert suggested but not sure if we need it just yet. Thanks for the tips though.