Android Test Tutorial: ActivityInstrumentationTestCase2 sample

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.