Excluding Time Duration of @BeforeEach and @AfterEach in JUnit5

300 views Asked by At

I Noticed, that JUnit5 @BeforeEach and @AfterEach is included into Test time duration. I am writing a Performance test, which results is presented on Jenkins Performance report, which takes data from JUnit5 results and draws a Graph, but problem is that it includes Time Duration of @BeforeEach and @AterEach stage. Example here:

public class TestClass
{
  @BeforeEach
  public void init()
  {
    Thread.sleep(10000)
  }

  @AfterEach
  public void cleanUp()
  {
    Thread.sleep(10000)
  }

  @Test
  void test1()
  {
    Thread.sleep(5000)
  }

  @Test
  void test2()
  {
    Thread.sleep(3000)
  }
}

Problem is, that duration of test1() is not 5000 Miliseconds but 25000(10000+10000+5000), and Duration of test2() is not 3000 Miliseconds but 23000 (10000+10000+3000).

Do you have any Ideas, how to Reset or Start/Stop test timer?

0

There are 0 answers