I'm facing a slight JUnit inconvenience regarding the run time for each test to run.
I have an @AfterClass
annotation and the last test that runs will get it's runtime added to it's.
So the report will incorrectly show a long run time for the poor test that happens to be run last.
Is there a way to exclude its run time from the last test?
This is an issue with Eclipse, not junit. If we use this as an example:
then we get for test1=4s, test2=10s (in Eclipse). However, the junit runner in Eclipse isn't using the information that junit is giving it. The RunListener interface defines methods testStarted, testFinished, testRunStarted, testRunFinished. If we look at when these methods are called, using:
we get the output:
which is what you would expect. Eclipse is adding the @afterClass onto the times. So, if you care about the timing of your methods, you need to either
How do you include/consider runtime in the last test?
If you are measuring performance, use a micro-benchmark. Check out junit-benchmark, I think it's one of the easiest micro-benchmarking libraries.