I try to use different instances for my tests but the first one is always used.
During the second test, it’s the content of the first instance that is displayed.
I don’t know where to look for.
public class MyActivityTest extends
ActivityInstrumentationTestCase2<MyActivity> {
private Solo solo;
public MyActivityTest() {
super(MyActivity.class);
}
protected void setUp() throws Exception {
super.setUp();
Authentication.setSessionId("mysessionid", this.getInstrumentation()
.getTargetContext().getApplicationContext());
solo = new Solo(getInstrumentation(), getActivity());
}
public void testFailFetching() {
CommunicationFactory.setInstance(MyActivityData.FALSE_QUIZCOMM_DEFAULT);
//some Solo tests
}
public void testSucceedFetching() {
CommunicationFactory.setInstance(MyActivity.CORRECT_QUIZCOMM_DEFAULT);
//some Solo tests
}
@Override
protected void tearDown() throws Exception {
CommunicationFactory.setInstance(null);
super.tearDown();
}
}
The
setUp()method will be called before each test. Provided it completes without throwing an exception (which presumably would abort your tests anyway), yoursolovariable is being reconstructed for each test. The follow test code demonstrates this:This prints:
It’s possible the
Soloobjects equal each other in the separate tests. But they won’t be the same object.