Disclaimer: I know this is a very bad design to actually have tests depend on each other to set any kind of variables. However I have to migrate these tests to Arquillian and rewriting everything is out of question.
Question: I have test methods that use some instance variables like this:
public int myNumber= 0;
@Test
public void testOne() {
// do something with myNumber
}
@Test(dependsOnMethods = "testOne")
public void testTwo {
// do something with myNumber
This used to work using the jboss microcontainer. But it doesn't, while running such test in-container using Arquillian. What is the easiest way to make this work again? Right now I simply made all the fields static, which works. Are there any negative consequences of that?
Edit: Cedric's suggestion doesn't work neither, which is probably due to the same reason instance variables don't work. Arquillian invokes the whole lifecycle for each @Test
method and it looks like it injects a new ITestContext
to each @Test
as well. This is what I tried:
Integer number = new Integer(10);
static final String NUMBER = "number";
@Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
public void testOne(ITestContext ctx) {
System.out.println("TEST ONE: " + number);
number += 100;
ctx.setAttribute(NUMBER, number);
System.out.println("CONTEXT " + ctx.getName());
System.out.println("CONTEXT " + ctx.getAttribute(NUMBER));
}
@Test(dependsOnMethods="testOne", dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
public void testTwo(ITestContext ctx) {
System.out.println("TEST TWO: " + number);
System.out.println("CONTEXT " + ctx.getName());
System.out.println("CONTEXT " + ctx.getAttribute(NUMBER));
}
And result:
TEST ONE: 10
CONTEXT Arquillian - class com.example.ServerTest
CONTEXT 110
TEST TWO: 10
CONTEXT Arquillian - class com.example.ServerTest
CONTEXT null