Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation to log the execution time of each test case in Junit5

I have a requirement to log the execution time for each test case. I don't want to use a custom implementation. I want to know whether there is an annotation available for this in junit5

Btw, I know about Stopwatch or Junit4 @Timeout.

like image 726
Anupama Boorlagadda Avatar asked Jan 29 '23 23:01

Anupama Boorlagadda


1 Answers

After a look through into junit5 documentation, I found this sample TimeExtension

This snippet is from their docs:

@ExtendWith(TimingExtension.class)
class TimingExtensionTests {

  @Test
  void sleep20ms() throws Exception {
     Thread.sleep(20);
  }

  @Test
  void sleep50ms() throws Exception {
    Thread.sleep(50);
  }

}

EDIT: Source code for TimingExtension

like image 154
Anupama Boorlagadda Avatar answered Feb 06 '23 06:02

Anupama Boorlagadda