ACTIVITYINSTRUMENTATIONTESTCASE2 is primarily used to test the functional testing of one or more activity, using and ultimately applying the same operating environment to test activity functions. You can use the normal system context (not a mock) to test the function of an activity. and allows you to create some mock Intent to test the response of the activity. It is important to note that this testcase does not allow you to use mock context and Application object tests, which means you must test with the environment in which the application actually runs.
The ActivityInstrumentationTestCase2 inheritance relationship is shown in the following illustration:
Its getactivity () method can get the instance object of the activity being tested.
public class Apidemostest
extends activityinstrumentationtestcase2<apidemos> {public
apidemostest () {
super (Apidemos.class);
}
public void Testactivitytestcasesetupproperly () {
assertnotnull (' activity should is
launched successfully ') Getactivity ());
}
Test method testactivitytestcasesetupproperly Use Getactivity (), the main purpose is to test the activity of this test can start normally, Test getactivity () is not empty.
In addition, ACTIVITYINSTRUMENTATIONTESTCASE2 also provides two methods:
Setactivityinitialtouchmode (Boolean) sets the Touchmode before starting the activity
Setactivityintent (Intent) can set the Intent object that initiates the activity to test the activity
See a full set of tutorials: http://www.bianceng.cn/OS/extra/201301/35252.htm