Is each test method created in its own instance of the test class with TestNG?

So, I thought the following code would work fine in TestNG, although this is not the case:

public class Tests { int i = 0; @Test public void testA() { Assert.assertEquals(0, i); ++i; } @Test public void testB() { Assert.assertEquals(0, i); ++i; } } 

Is there a way to get TestNG to run a new Tests class for each test method?

+6
source share
1 answer

A common solution is to use the @BeforeMethod method to set up the testing status,

 @BeforeMethod public void setup() { i = 0; } 
+4
source

Source: https://habr.com/ru/post/887012/


All Articles