01. Android basics and 01android Basics

Source: Internet
Author: User

01. Android basics and 01android Basics
1.1. Classic Structure

Btn_button = (Button) findViewById (R. id. btn_button); btn_button.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Toast. makeText (MainActivity. this, "the button is clicked", Toast. LENGTH_SHORT ). show ();}});

2. Internal class as listener

Class MyClickListener implements OnClickListener {@ Override public void onClick (View v) {Toast. makeText (MainActivity. this, "the button is clicked", Toast. LENGTH_SHORT ). show () ;}// set the listener btn_button.setOnClickListener (new MyClickListener ());

3. Specify listener Layout

// You need to set the onclick event public void click (View view) {Toast. makeText (MainActivity. this, "the button is clicked", Toast. LENGTH_SHORT ). show ();}

4. listener for the current class

Public class MainActivity extends Activity implements OnClickListener {private Button btn_button; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); btn_button = (Button) findViewById (R. id. btn_button); btn_button.setOnClickListener (this) ;}@ Override public void onClick (View v) {Toast. makeText (MainActivity. this, "the button is clicked", Toast. LENGTH_SHORT ). show ();}}
1.8 unit test
  • Black box testing: Tests are performed based on the ing between input and output data from the user's perspective.
  • White box testing: Also known as structure testing, transparent box testing, logic-driven testing, or code-based testing.
  • Unit Test: Module testing is a short piece of code written by developers to check whether a very small and clear function of the tested code is correct.
  • Function Testing: Test the features and operational behaviors of a product based on product features, operation descriptions, and user solutions to determine whether they meet the design requirements.
  • Stress Testing: The subject assigns a certain number of tasks and jobs to the observer to observe the individual's completion of the task.
  • Integration Test: Logical extension of unit test.

A) first, we need to write the method to be tested, define a CalService class, and write the add () method.

public class CalService {    public int add(int a,int b){        return a + b;    }}

B) Compile the test class to inherit AndroidTestCase, and write the test method. The modifier is public, and an Exception is thrown directly to the test framework throws Exception, and no return value is allowed. Assert again

public class TestCalService extends AndroidTestCase {    public void testAdd() throws Exception{        CalService calService = new CalService();        int result = calService.add(2, 8);        assertEquals(10, result);    }}

C) configure the AndroidManifest. xml file

Run the test method and start the test. Green bars indicate that the test has passed, and red bars indicate that the test has failed.

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.