📜 ⬆️ ⬇️

Covering graphs in software testing, part 1


Most programs and algorithms can be represented as a graph consisting of a set of vertices ( N ) and edges ( E ). Coverage of graphs in testing is useful because you can design tests using different coverage criteria and identify errors. With regard to testing the black box, then covering graphs here can also be of great importance if you have to work with states and transitions, entity state graphs, etc. If the graph is rather complicated, different coverage criteria will allow assessing the sufficiency of the test suite.


Definitions


Counts

The formal definition of a graph is given below.


Ways in the graph

The graph below is for illustrating the definitions given.

')

Vertex Coverage (PV)


The simplest coverage criteria are vertex and edge finishes. Covering the vertices assumes that your tests cover all the reachable vertices in the graph. Requirements for test coverage of vertices in a graph are the set of vertices (N) of a graph.



For this graph, the requirements and the test path satisfying them are given below.

requirements = {1, 2, 3}
path (T) = {[1, 2, 3]}

Rib Coating (PR)


The purpose of covering the edges is to go through all the edges in the graph. An edge can be expressed as a path of length 1. The requirements contain all attainable paths of length up to 1 (and inclusive). The wording “to 1” allows to take into account graphs consisting of one vertex and not having edges.

requirements = {(1, 2), (1, 3), (2, 3)}
path (T) = {[1, 2, 3], [1, 3]}

The tops of the vertices and the edges are most often the same. The exceptions are special cases, including conditional constructions (if-else). (This is the three-vertex graph in the example above: compare the required test paths and see why.)

Paired Rib Coating


Requirements include every reachable path of length up to 2 inclusive.
In fact, find all paths that include three vertices and two edges and create a set of test cases covering these paths. Paths of length 1 will be automatically covered as they will be included in one of these test paths. If there is a path of length 1 that is not a segment of the paths already listed, you need to include it in the list.



In the graph above there are five different pairs of ribs. Pairing the ribs suggests that each of these pairs is covered by at least one test path.

requirements = {[1, 3, 5], [1, 2, 3], [1, 2, 4], [2, 3, 5], [2, 4, 5]}
path (T) = {[1, 3, 5], [1, 2, 3, 5], [1, 2, 4, 5]}

Full track coverage (SPT)


Requirements include all paths in G. This is not possible if there is a cycle in the graph. As a compromise, the covering of established paths is used.

Covering specified paths (PPP)


In the PPP, the requirements are a set of S test paths, where S is the set of paths chosen by the tester. This avoids the problem of having to cover infinitely many paths in the RFP if the graph contains a cycle. In the PPP, the tester simply eliminates the cycle from S , and the requirements of the PPP can be satisfied.



S = {[1, 2, 3], [1, 3], [1, 4, 3]} (All paths in G, except those containing cycles)
requirements = {[1, 2, 3], [1, 3], [1, 4, 3]}
path (T) = {[1, 2, 3], [1, 3], [1, 4, 3]}

SPT impractical. The PPP is a weak compromise to actually satisfy the RFP without adding an infinite set of requirements for graphs with cycles. However, covering the specified paths is also imperfect. A tester can skip important paths when making a set of S , which leads to a subjective and error-resistant MFR.

Attempts to solve this problem have been made for a long time. Starting from a single cycle (1970s), passing each cycle exactly once (1980s) to a less formal description — passing each cycle 0, 1 or more times (1990s), software testers came up with the idea of ​​using basic paths to limit the total number of paths in the graph.

Note in the fields: the cyclomatic complexity of the graph determines the number of tests necessary for all the lines in the program to be executed at least once. Cyclomatic complexity can be calculated by adding 2 to the difference between the number of edges and vertices in the graph.

CA = # edges - # vertices + 2

In the next and last part: the main paths and coverage associated with them.

Source: https://habr.com/ru/post/271991/


All Articles