<span id="Label3"></p><p><p>1, before the unit test must first be configured in Androidmanifest.xml:<br></p></p><p><p><br></p></p><p><p>(1) <!--place instruction set under the root node manifest node instrumentation</p></p><p><p><instrumentation</p></p><p><p>Android:name= "android.test.InstrumentationTestRunner"</p></p><p><p>Android:label= "Tests for My App"</p></p><p><p>Android:targetpackage= "com.xunfang.junit"/></p></p><p><p>These are the starting devices that represent the framework of unit tests, which have several types of starter devices, which are used by Default.<br></p></p><p><p><br></p></p><p><p>The targetpackage is the same as the package above for the unit test to be in the same process as the current application</p></p><p><p><br></p></p><p><p>(2) <!--the function library used by the application node---</p></p><p><p><uses-library android:name= "android.test.runner"/></p></p><p><p><br></p></p><p><p>function libraries that represent unit tests<br></p></p><p><p><br></p></p><p><p>Attached code:</p></p><p><p>Configuration in Androidmanifest.xml:</p></p><p><p><br></p></p><p><p><uses-sdk</p></p><p><p>android:minsdkversion= "14"</p></p><p><p>android:targetsdkversion= "/>"</p></p><p><p><strong><!--configured in Manifest</strong> --</p></p><p><p><span style="background-color:rgb(146,208,80);"><instrumentation</span></p></p><p><p><span style="background-color:rgb(146,208,80);">Android:name= "android.test.InstrumentationTestRunner"</span></p></p><p><p><span style="background-color:rgb(146,208,80);">Android:targetpackage= "com.xunfang.junit" ></span></p></p><p><p><span style="background-color:rgb(146,208,80);"></instrumentation></span></p></p><p><p><br></p></p><p><p><application</p></p><p><p>android:allowbackup= "true"</p></p><p><p>android:icon= "@drawable/ic_launcher"</p></p><p><p>Android:label= "@string/app_name"</p></p><p><p>Android:theme= "@style/apptheme" ></p></p><p><p><strong><!--configured in the Application tab</strong> --</p></p><p><p><span style="background-color:rgb(146,208,80);"><uses-library android:name= "android.test.runner"/></span></p></p><p><p><activity</p></p><p><p>Android:name= ". Mainactivity "</p></p><p><p>Android:label= "@string/app_name" ></p></p><p><p><intent-filter></p></p><p><p><action android:name= "android.intent.action.MAIN"/></p></p><p><p><br></p></p><p><p><category android:name= "android.intent.category.LAUNCHER"/></p></p><p><p></intent-filter></p></p><p><p></activity></p></p><p><p></application></p></p><p><p>The above two paragraphs have a background color that is configured in the global file configuration</p></p><p><p><br></p></p><p><p>Code in the business Logic:</p></p><p><p></p></p><p><p>public class MyMath {</p></p><p><p><br></p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span> public int add (int a, int B) {</p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span> return a + b;</p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span>}</p></p><p><p>}</p></p><p><p><br></p></p><p><p>Unit Test Code:<br></p></p><p><p>public class Myjunitetestcase extends Androidtestcase {</p></p><p><p><br></p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span> public void test () {</p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span> MyMath my = new MyMath ();</p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span> assertequals (my.add (4, 6));</p></p><p><p><span class="Apple-tab-span" style="white-space:pre;"></span>}</p></p><p><p>}</p></p><p><p><br></p></p><p><p>Test Steps:</p></p><p><p>(1) project-"right button"-"Run as--" Android jutil Test<br></p></p><p><p>(2) Open Unit Test Code-"select the method you want to test in outline-" right--"Run as--" Android jutil test</p></p><p><p>This article is from the "beginner" blog, so be sure to keep this source http://10154241.blog.51cto.com/10144241/1663841</p></p><p><p>Unit Tests for Android apps</p></p></span>
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