Use JUnit to make a monomer test analysis

xiaoxiao2021-03-06  56

Use JUnit to analyze the analysis of monomer test 1. The advantages and disadvantages of JUnit 1. Advantages · JUnit Test allows you to develop a higher quality code faster. · JUnit Test Checks their own operations and provides timely feedback. · JUnit test can be organized into multiple test kits that are hierarchical. · You can write JUnit test cases quickly and cheap. · Developers can easily complete the JUnit test. · JUnit test is written in Java. · JUnit can test EJBS, servlets, and thread programs. · JUnit is designed around two main design modes: command mode and composite mode. · Junit is free. 2. Disadvantages · JUnit does not separate test data from the test code. · JUnit does not unit test of Swing Guis, JSPS or HTML. · JUnit test cannot replace functional tests. Even if your unit test is successful, it does not mean that your software is ready. · JUnit can not be able to test the Java code of the server side. Several XUnit test frameworks are designed to use the unit test server-side Java code. two. Suggestions using junit write test cases A lot of Test code for JUnit is a lot of test code, but the number of BUGs in the IT phase is still larger than the planned value, and the principle of writing test cases using JUnit is recommended as follows, try to achieve The amount of JUnit code is used in the case where no omissions are missed.

1. Use the path analysis to combine boundary conditions to ensure that all statements of the test code are executed at least once. Example: The flowchart of a method is shown below:

1 Find a stand-alone path according to the flowchart, and draw a flow map, the corresponding flow graph in the previous example is as follows:

Where: each circle, called a flowchart, represents one or more statements, the processing box sequence and the diamond decision box in the flowchart can be mapped into a node, the arrow in the flowchart, called edge or connection, Represents the control flow, similar to the arrow in the flowchart. One side must terminate in a node, even if the node does not represent any statement, the range of edges and nodes is referred to as the area. 2 Get a set of independent paths according to the flow graph, the collection of separate paths of the above example is as follows: Path 1: 1-11 Path 2: 1-2-3-4-5-10-1-11 Path 3: 1-2-2- 3-6-8-9-10-11 Path 4: 1-2-3-6-7-9-10-1-11

3 Writing test cases for each independent path 4 can calculate the upper bound of the independent path by one of the three methods: 1. V = E-N 2, E is the number of sides in the flow map, N is flow map Number of nodes. 2. V = P 1, P is the number of judgments in the flow map G 3. V = R, R is the number of regions in the flow map

For example, the (B) flow diagram can use any of the above algorithms to calculate the number of independent paths 1.4440, so V = 42. v = 11 strip -9 nodes 2 = 43. V = Three decision nodes 1 = 4 Thus, in order to overwrite all program statements, at least 4 tests must be designed to run in these 4 paths. 5 Write other test cases for input data using boundary value method

2. For some SET / GET methods such as ordinary bean classes, just a simple package Java API, no complex logic and algorithms do not need to write JUnit test cases.

转载请注明原文地址:https://www.9cbs.com/read-118251.html

New Post(0)