Android Test---JUnit

Source: Internet
Author: User

JUnit Unit Test

Android Unit Test base is also relatively simple, but also the test Add method is correct, test case or with a? = 2 A few simple Android unit tests;

1. Open Eclipse and create a new project. Click on the menu bar file-"new-" Java project;project name is testjunit;

2. Right-click on the newly created Project Testjunit, select New---Java class, create a Java category; class name is addclass;

The Java program to be tested is as follows

 Public class addclass {    public  addclass () {        //  TODO auto-generated Constructor Stub    }     publicint addf (int one,int  ) {          return one+;     }}

3. Next, you can write junit test cases;

3.1. Right-click on the project Testjnit, select new-"JUnit Test case,

3.2 Select New JUnit test 3 or new JUnit Test 4 in the New Juit test Case dialog box that pops up.

Then in the new JUnit test case name, enter the names of the test cases such as "Testaddcase" click Finish; (Of course you can choose a method like SetUp (), TearDown ())

3.3 Write test case in Testaddcase.java if it equals 2

Importjunit.framework.TestCase; Public classTestaddcaseextendsTestCase {protected voidSetUp ()throwsException {System.out.println ("Test Prep"); }    protected voidTearDown ()throwsException {System.out.println ("End of Test"); }     Public voidTestadd () {assertequals (2,NewAddClass (). ADDF ()); }}

4. Finally start the execution of the test case;

Right-click Project Select Run as----"JUnit Test"

5. View the results of the test;

Android Test---JUnit

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.