Java – is there a way to start and stop recording multiline statements and execution time?
•
Java
Suppose I have a unit test like this:
@Test public void testSomething(){ Car car = new Car(); car.setColor("blue"); car.setSize("big"); }
I want to see how long it takes to execute a statement. Is there a "log with timer" function, as shown below, to record each statement it has executed (and its time spent)?
@Test public void testSomething(){ logWithTimer.start(); Car car = new Car(); car.setColor("blue"); car.setSize("big"); logWithTimer.finish(); }
So when I run the above unit test, the output will be as follows:
15:23:456 Car car = new Car(); 15:23:470 car.setColor("blue"); 15:23:500 car.setSize("big");
Solution
Take a look at JUnit 5 with timing extension. It may be what you need: http://junit.org/junit5/docs/current/user-guide/#extensions -lifecycle-callbacks-timing-extension
You can use annotations to make JUnit display timing data about test methods in this class
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码