There is, in JUnit, intreface called TestListener
. JUnit provides some implementations that were attached to each test run. One of those implementations is internal Listener
class in Result
class. It calculates time in that way
public void testRunStarted(Description description) throws Exception {
startTime.set(System.currentTimeMillis());
}
@Override
public void testRunFinished(Result result) throws Exception {
long endTime = System.currentTimeMillis();
runTime.addAndGet(endTime - startTime.get());
}
Code taken from org.junit.runner.Result
JUnit 4.12.
After calculation JUnit publish "report" that contains all Result
s of tests. IDEs like Eclipse or Idea attach to test JUnit they implementations of TestListener
that could parse&show "report". Finally listeners from IDE send message to IDE window and you could see test result and time.