Android uses its own Junit to create a test project, androidjunit

Source: Internet
Author: User

Android uses its own Junit to create a test project, androidjunit

1. Create an Android Project

Package com. shellway. junit; public class Service {public int divide (int a, int B) {return a/B ;}}Service. java. package com. shellway. junit; import junit. framework. assert; import android. test. androidTestCase; public class TestT extends AndroidTestCase {public void test1 () {Service service Service = new Service (); System. out. println (service. divide (10, 2);} public void test2 () {Service service = new Service (); System. out. println (service. divide (10, 0);} public void test3 () {Service service = new Service (); Assert. assertEquals (2.5, service. divide (10, 4 ));}}TestT inherits AndroidTestCase and serves as a test class <? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "com. shellway. junit "android: versionCode =" 1 "android: versionName =" 1.0 "> <uses-sdk android: minSdkVersion =" 16 "android: targetSdkVersion = "21"/> <instrumentation android: targetPackage = "com. shellway. junit "android: name =" android. test. instrumentationTestRunner "/> <application android: allowBackup =" true "android: icon =" @ drawable/ic_launcher "android: label =" @ string/app_name "android: theme = "@ style/AppTheme"> <uses-library android: name = "android. test. runner "/> <activity android: name = ". mainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> </application> </manifest>AndroidManifest. xml

Note: The content to be added to the configuration file is:

<Instrumentation android: targetPackage = "com. shellway. junit "android: name =" android. test. instrumentationTestRunner "/> <uses-library android: name =" android. test. runner "/>View Code

Pay attention to the location where they join. This is a way to test your own project.

Another method is to create an Android Junit project to Test another project. Note that the Test project name cannot be named as Test, otherwise, it is difficult to find the problem. The error information for the project named "Test" is shown below.

 


Junit4 can test android Projects

Yes. There is a junit unit test corresponding to android development, which has nothing to do with the junit version. For more information, see mobile.51cto.com/android-229614.htm.

Help me use android junit test to test the problem comments.

Check what is reported first.

Related Article

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.