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.