Record time it takes JUnit tests to run

后端 未结 7 1459
无人共我
无人共我 2021-02-04 11:52

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

7条回答
  •  没有蜡笔的小新
    2021-02-04 12:32

    If you use @Before and @After annotations and note the junit testcase start and endtime. Then finding the difference of two timestamps should give you the testcase execution time. Something like this:

     public class Example {
    
        long startTime;
        long endTime;
    
        @Before public void recordStartTime() {
            startTime = System.currentTimeMillis();
        }
        @Test public void testSomething() {
              //test method
        }
        @After public void recordEndAndExecutionTime() {
            endTime = System.currentTimeMillis();
            System.out.println("Last testcase exection time in millisecond : " + (endTime - startTime));
        }
     }
    

提交回复
热议问题