Xml & json format a data entry and analysis

 

A unit test method

https://blog.csdn.net/yingaizhu/article/details/80297087

1.1 Adding Unit Test dependencies

    Program modules need to be introduced in the following build.gradle dependencies: Usually will automatically generate new project Androidstudio

testImplementation- dependence is introduced java unit test unit, the test unit is running on the current PC jvm;

androidTestImplementation- dependence is introduced Android unit testing, unit testing Android running environment.

1.2 to add test code directory

    If AndroidStudio current project view Android, need to switch to Project View, add androidTest / java (Android unit tests run in the Android environment unit test) (the JUnit unit tests run, and test / java under program modules following src directory the current tests on computer unit JVM), and then add the test class and package names inside.

 

 

 

  • androidTest / java (Android unit testing, unit tests run on the current computer, jvm, when performing the test requires Android connection device, more slowly, Android API need to call for unit testing)
  • test / java (JUnit unit testing, do not need to put the unit test class dependent Android, unit tests run on a computer, jvm current, speed, just for java code functional unit test)

1.3 Adding Unit Test Class

1.3.1 manually write unit test classes

1.3.1.1 androidTest test class

    androidTest class is used for the test relies Android API unit testing, the Android device needs to be connected for testing. The new class to add androidTest java @RunWith (AndroidJUnit4.class) annotations, if the class method is a method to add test access @Test annotations.
Sample Code: Path app \ src \ androidTest \ java \ com \ example \ itandroid_1

public class MainActivityTest {

    private Context mTargetContext;

    @Before
    public void setUP() throws Exception {
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    }

    @Test
    public void onCreate() {
        try { ApplicationInfo applicationInfo = mTargetContext.getPackageManager().getApplicationInfo(mTargetContext.getPackageName(), PackageManager.GET_META_DATA); Bundle metaData = applicationInfo.metaData; String data = metaData.getString("com.panzq.Androidtest"); assertEquals("123456", data); } catch(PackageManager.NameNotFoundException e) {e.printStackTrace (); }}}

1.3.1.2 test test class

    test applicable to pure java class test unit tests run in the current environment of the device jvm, to test the device without Android. New test java class class method if the method is to add test access @Test annotations.
Code Example: Path app \ src \ test \ java \ com \ example \ itandroid_1
public class TestUtil {
    @Before
    public void setUp() throws Exception {

    }

    @Test
    public void isEmpty() {
        assertEquals(true, TextUtils.isEmpty(""));
    }
}

 

Test Method setUp class 1.3.1.3

    In the setUp method to test class can be tested before the start of some initialization, such as the test class variables initialization, this method needs to be added @Before comment.

Description:
The sample code above assertEquals be used directly, because of the use of static import method of introducing the corresponding packet; (import static org.junit.Assert *.)
The test features and rational use androidTest Test, test efficiency increasing unit .
2.2 automatic generation of test classes and test methods
        described above and the test class is manually add the test method, the following describes the automatic generation of test classes and methods. In the source project, select the required class and add unit tests open, the display area "right" in the content -> "Go To", the pop-up window, select "Test", the pop-up window, select "Create New Test .... .. "

 

 

 In the following dialog box, the check unit testing method needs to be added, where there is a "Generate" General method for generating, may be selected setUp / @ Before (before starting the call, can be used to initialize) and tearDown / @ After ( after the call)

 

 

1.3 running unit tests

1.3.1 run a single test method

    Test methods within the title, "right", the pop-up menu, select "Run method name" can be (unit tests can also use breakpoint debugging and performance tuning).

 

 

1.3.2 Batch running the test method (may not be achieved in some cases)    

  After the test task, can perform all of the unit test method (Terminal running in AndroidStudio gradlew test, the test run gradle -p path item, gradle environment variable is not configured, the system requires absolute path terminal) terminal using gradle run, run to completion , all cells will run test methods, and the results are displayed, as shown below:

 

 

Two XML syntax 

<? xml Version = "1.0" encoding = "UTF-8"?> 
<China> 
    <Beijing> 
        <Changping> </ Changping> 
        <Haidian> </ Haidian> 
    </ Beijing> 
</ China>

2.1 document declaration

<? xml version = "1.0" encoding = "utf-8"?> document declaration must be written in the first row of 
the same coding save save save coding time xml declaration keep files, if you do not declare a default encoding utf-8

2.2 elements

<China> 
    <Beijing> 
        <Changping> </ Changping> 
        <Haidian> </ Haidian> 
    </ Beijing> 
</ China>

 

2.3 Properties

1. In the write attribute start tag

2. Name the rule properties like naming elements

3. The property must use quotation marks to wrap, double quotes can be single quotes

4. The content attribute may be represented in the form of a sub-tag

2.4 Notes

<! - Comment ->

Note CDATA may comprise greater than less-than, not parser

<! [CDATA [<Beijing> </ Beijing>]]>

2.5 special character escape

Special characters Special characters
& &amp;
< &lt;
> &gt;
" &quot;
' &apos;

 

2.6 a schema

https://www.w3school.com.cn/schema/schema_howto.asp

 

2.7 Dom parsing

 

Guess you like

Origin www.cnblogs.com/qiangge-python/p/11828946.html