Introduction to the testing framework in Android, android framework

Source: Internet
Author: User

Introduction to the testing framework in Android, android framework
Test

Good programs are tested.

Purpose: To test as many bugs as possible in the program.

Testing is divided

Black box test: Test business logic

White-box test: test the logic method. Generally, you can write a script code to call the business logic method.

According to the test granularity:

Method test: function test tests a method.

Unit test: unit test tests multiple methods of a class or a unit.

Integration test: the integration testv server and the client perform joint debugging. Multiple Units are tested.

System test tests the functions of the entire system. All units are tested together.

Divided:

Smoke test: the smoke test program runs under high load without memory overflow or error, which indicates that the program is normal.

Stress test: pressure test simulates a certain number of users to connect to the server to see if the server is down.

 

Regression testing: After modifying the old code, you can re-test it to confirm that the modification does not introduce new errors or cause errors in other codes.


Unit Test

In Android, by integrating AndroidTestCase class table names, a class is a test class.

Each method in the test class can be run independently.

In Android, when performing unit tests, you must add the test instruction set or test class library to the list file. Add the application tag before the application tag.



The test framework and its definition are irrelevant to the project to be tested.

 

The test method is a fixed public access permission with no return value. The method name generally starts with "test" in lower case. The name of the method to be tested.

Definition Format: public void test method name (){}

When testing a method in the testing framework, do not run the project. Just run the testing method, but you must open the simulator or connect to the mobile phone.

The unit test framework can also be used in Android.

Package com. test. unittestdemo. utils;

 

Public class Utils {

Public static int add (int a, int B ){

Return a + B;

}

}

 

Package com. test. unittestdemo. test;

 

Import com. test. unittestdemo. utils. Utils;

 

Import android. test. AndroidTestCase;

 

Public class TestCase extends AndroidTestCase {

Public void test (){

Int result = Utils. add (10, 5 );

// Assertion: used to check whether the actual value is consistent with the expected value. The first value is the expected value, and the second value is the actual value.

// Methods without return values. assertions have no practical significance.

// Method without return value. Generally, the test is to check whether the business logic is normal.

AssertEquals (15, result );

}

}

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.