I am new to TestNG. I am writing classes containing a unit test case for spring boot application, and running them using eclipse TestNG plugin. For every different api or method I need to create different class containing test. Can we avoid creating different classes everytime? If yes please guide how can I write.
Below is code snippet for one of the api,
@SpringBootTest
@DirtiesContext
public class TestAdd {
private Integer id;
@BeforeTest
public void beforeAddReturnsObjectTest() {
}
@Test
public void testAddReturnsObject() throws Exception {
Test1 test1 = new Test1();
test1.setName("Mohit");
ResponseEntity<Test1> entity = new TestRestTemplate()
.postForEntity("http://localhost:8080/test/", test1, Test1.class);
id = entity.getBody().getId();
assertThat(entity.getBody().getName()).isEqualTo(test1.getName());
}
@AfterTest
public void AfterAddReturnsObjectTest() {
TestRestTemplate entity = new TestRestTemplate();
entity.delete("http://localhost:8080/test/" + id, Test1.class);
}
}
Any help would be appreciated!!