Cedric,
Thank you for the quick response.
Re base class: this only works well if I only have one fixture that my
test class depends on (as you can probably tell by now, these tests
are more 'integration' than unit). I guess there is a possibility of
each test requiring any fixture to extend a common 'FixtureProvider'
base class which starts up and tears down a bunch of fixtures based on
parameters or even custom annotations - but to me thats starting to
lend more towards a 'test framework' feature than something one would
implement themselves.
Re junit Rules: I had not looked at them before, but now that you have
mentioned it @ClassRule from junit does almost exactly what I want -
ala:
class TestA1{
@ClassRule
public static FixtureX = new FixtureX();
@Test
public void testA1a(){};
@Test
public void testA1b(){};
}
class TestB1{
@ClassRule
public static FixtureX = new FixtureX();
@ClassRule
public static FixtureY = new FixtureY();
@Test
public void testB1a(){};
@Test
public void testB1b(){};
}
I guess one could argue that testng provides a near equivalent with
something like the sample below, however the @Rule / @ClassRule
annotation does seem to lend to a slightly cleaner test.
class TestA1{
@BeforeClass
public void setupFixtures(){
FixtureX.before()
}
@AfterClass
public void teardDownFixtures(){
FixtureX.after()
}
@Test
public void testA1a(){};
@Test
public void testA1b(){};
}
class TestB1{
@BeforeClass
public void setupFixtures(){
FixtureX.setUp();
FixtureY.setUp()
}
@AfterClass
public void teardDownFixtures(){
FixtureX.tearDown()
FixtureY.tearDown()
}
@Test
public void testB1a(){};
@Test
public void testB1b(){};
}
Based on the (very verbose) examples above - would you consider this
use case as something to support at the testng framework level?
best,
./A