Perform unit tests for Android projects in eclipse (Chuanzhi podcast video notes)

Source: Internet
Author: User

Androidmanifest. xml file content:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. sinaapp. ssun "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> </P> <p> <uses-SDK Android: minsdkversion = "8"/> </P> <p> <application <br/> Android: icon = "@ drawable/ic_launcher" <br/> Android: label = "@ string/app_name"> <br/> <activity <br/> Android: Name = ". androidjunitactivity "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> </P> <p> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> <uses-library Android: Name =" android. test. runner "/> <br/> </Application> <br/> <instrumentation Android: Name =" android. test. instrumentationtestrunner "<br/> Android: targetpackage =" com. sinaapp. ssun "/> <br/> </manifest> </P> <p>

Service. Java source code:

Package COM. sinaapp. ssun; </P> <p> public class services {<br/> Public void save (string Str) {<br/> Str. substring (6); <br/>}</P> <p> Public int add (int A, int B) {<br/> return A + B; <br/>}< br/>
JUnit. Java source code:

Package COM. sinaapp. test; </P> <p> Import JUnit. framework. assert; <br/> Import android. test. androidtestcase; <br/> Import android. util. log; </P> <p> Import COM. sinaapp. ssun. services; </P> <p> public class JUnit extends androidtestcase {<br/> Public void testsave () throws throwable {<br/> services SER = new services (); <br/> Ser. save (null); <br/>}</P> <p> Public void testadd () throws throwable {<br/> services SER = new services (); <br/> int actual = Ser. add (1, 3); <br/> assert. assertequals (3, actual); <br/>}</P> <p> Public void testlog () {<br/> log. I ("testlog", "hello"); <br/>}< br/>
Androidjunitactivity. Java source code:

Package COM. sinaapp. ssun; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; </P> <p> public class androidjunitactivity extends activity {<br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/>}< br/>}

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.