I would like to record how long it takes my JUnit test to run programmatically. I have a large number of tests in various test classes, and I would like to find out how long ea
In addition to existing answers, you can use a rule for test name along with Before
and After
methods to display method name on log. Like this:
public class ImageSavingTest {
@Rule
public TestName name = new TestName();
private long start;
@Before
public void start() {
start = System.currentTimeMillis();
}
@After
public void end() {
System.out.println("Test " + name.getMethodName() + " took " + (System.currentTimeMillis() - start) + " ms");
}
@Test
public void foobar() {
// test code here
}
}
Will output:
Test foobar took 1828 ms