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