What I want to do is
- define dependencies on test methods (TestNG)
- define for each test method if the test fixture is shared (not reset) or re-created before the test method runs
See the following example:
- test1 would be run first
- if test1 succeeds then test2 is run and uses the same data that test1 inserted
- if test2 succeeds then test3 is run and uses the date from test1 and test2
if test3 succeeds then test4 is run but test4 starts with a clean state, it will not share the same fixture
public class SomeTestClass extends Insertable { @BeforeSuite public void background() { insert(0); } @Test() public void test1() { // when insert(1); // then assertThatIsContained(0); assertThatIsContained(1); } @Test(dependsOnMethods = {"test1"}) @SharedFixture public void test2() { // when insert(2); // then assertThatIsContained(0); assertThatIsContained(1); assertThatIsContained(2); } @Test(dependsOnMethods = {"test2"}) @SharedFixture public void test3() { // when insert(3); // then assertThatIsContained(0); assertThatIsContained(1); assertThatIsContained(2); assertThatIsContained(3); } @Test(dependsOnMethods = {"test2"}) @FreshFixture public void test4() { // given insert(99); // when insert(4); // then assertThatIsNotContained(1); assertThatIsNotContained(2); assertThatIsNotContained(3); assertThatIsContained(0); assertThatIsContained(99); assertThatIsContained(4); }
}