Create a new test project with the JUnit that you carry in Android

Source: Internet
Author: User

1. Build a new Android project

 Package Com.shellway.junit;  Public class Service {      publicint divide (int A,int  b) {            Return A/b;      }}
Service.java. As the class being tested
 PackageCom.shellway.junit;ImportJunit.framework.Assert;Importandroid.test.AndroidTestCase; Public classTesttextendsAndroidtestcase { Public voidtest1 () {Service service=NewService (); System.out.println (Service.divide (10, 2)); }     Public voidtest2 () {Service service=NewService (); System.out.println (Service.divide (10, 0)); }     Public voidtest3 () {Service service=NewService (); Assert.assertequals (2.5, Service.divide (10, 4)); }}
Testt inherits Androidtestcase, as a test class
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.shellway.junit"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "+"android:targetsdkversion= "+" />       <InstrumentationAndroid:targetpackage= "Com.shellway.junit"Android:name= "Android.test.InstrumentationTestRunner" />        <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <uses-libraryAndroid:name= "Android.test.runner" />        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>
Androidmanifest.xml

Note: The content to be included in the configuration file is:

< Instrumentation       Android:targetpackage = "Com.shellway.junit"       android:name= "Android.test.InstrumentationTestRunner"/><   android:name= "Android.test.runner"/>
View Code

and pay attention to where they are joining. This is a way to test your own engineering.

Another way is to create a new Android JUnit project to test another project, it is important to note that when you build this test project name can not be named by test, or the error will be difficult to find out the problem, the following is a test to name the project error message.

Create a new test project with the JUnit that you carry in Android

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.