Introduction to the use of test framework in Android

Source: Internet
Author: User

Test

The good procedure is measured.

Purpose of the test: test out as many bugsas possible in the program.

Test is divided into

Black Box testing: Testing business logic

White box test: Test logic method. In general, write a script code to invoke the business logic method through scripting code.

According to the test granularity is divided into :

Method Test:function Test tests a method

Unit tests: Unit Test Multiple methods for testing a class or a unit

Integration testing:integration Testv Server and client joint debugging, testing multiple units.

The system test is the function of the whole system, and all the units are tested together .

According to the degree of violence tested, divided into:

Smoke test: TheSmoke Test program runs in a high-load state with no memory overflow or error, indicating that the program is normal.

Stress test:pressure test simulates a certain amount of user connection to the server to see if the server will be down.

regression test : after modifying the old code, re-test to confirm that the modification did not introduce a new error or cause other code to produce an error.


Unit Test

In Android , A class that integrates the Androidtestcase class table name is a test class.

Each method in the test class can be run independently.

In Android , when you do unit testing, you need to add a test instruction set to the manifest file or a test class library to use. added before the application tag.



It doesn't matter where the test framework is defined or what it is to test the project.

The test method is a fixed public access permission, with no return value. The method name usually begins with a lowercase test . It is followed by the name of the method to be tested.

The definition format is public void Test method name () {}

When testing a method in the test framework, do not run the project, just run the test method, but you must open the emulator or connect to a real phone.

You can also use the Unit test framework in Android .

Package com.test.unittestdemo.utils;

Public class Utils {

Public Static int Add(intA,intb) {

return A + b;

}

}

Package com.test.unittestdemo.test;

Import com.test.unittestdemo.utils.Utils;

Import android.test.AndroidTestCase;

public   class   testcase   extends   Androidtestcase  {

Span style= "font-family: Song body; Color: #7f055; Font-weight:bold; Font-size:12.0000pt ">    public   void   test Span style= "font-family: Song body; Color: #000000; Font-size:12.0000pt "> () {

Span style= "font-family: Song body; Color: #000000; Font-size:12.0000pt ">         int   result  =  utils add (10, 5);

assertion: Used to detect consistency between actual and expected values, first value is expected, second value is actual value

There is no way to return a value, the assertion has no actual meaning

Span style= "font-family: Song body; Color: #000000; Font-size:12.0000pt ">          // There is no way to return a value, the general test is whether the business logic of the period is normal

assertequals ( result);

}

}

Introduction to the use of test framework in Android

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.