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.