This is how one of my test classes is structured:
public class DocumentQueryApiTests {
@BeforeMethod(alwaysRun = true)
public void tryingThisDamnThing() {
CoreHelper.editDocumentHeader();
}
@BeforeClass(alwaysRun = true)
public void createApi() {
CoreHelper.createApis();
}
@Description(...)
@Severity(....)
@Test()
public void shouldSee200AfterGetDocumentType() {
//cut because not relevant
}
@Description(...)
@Severity(....)
@Test()
public void shouldSee404...() {
//as above
}
@Description(...)
@Severity(....)
@Test()
public void shouldSee200....() {
//more code
}
//80 more tests
}
This is editHeader():
public static void editDocumentHeader() {
documentTypeQueryApi.reqSpec(new Consumer<RequestSpecBuilder>() {
public void accept(RequestSpecBuilder requestSpecBuilder) {
requestSpecBuilder.addHeader("company_id", DPCommon.provideCompany().toString());
}
});
}
When I run the class in IntelliJ, it'll run all methods as a single test. @BeforeMethod
(and @BeforeTest
, and any other @Before
tag) will be executed exactly once. Only one test will have company_id added to it's header.