What is model-based testing?

Model-based testing is a testing method in the field of software testing. The steps of MBT are as follows:

Conventional testing generally involves humans designing several specific test scenarios and then asserting the test results. Test cases fixed. Lack of uncertainty. Model-based testing requires implementing a model, and then formulating the relationship between behavior and behavior and the relationship between behavior and system (finite state machine), and then testing the system according to the state of the system under test and the previously set Restrictions and strategies are used to generate many use cases (the generated use cases will be different each time it is executed). The test results are affected by a series of operations, which can produce uncertainty, and it is more likely to find BUGs in some unexpected deep paths.

Model-based testing mainly includes the following parts:

1. Model Program: Here you define some operations (actions) that can be performed on the system under test, such as creating a virtual machine, deleting a virtual machine, etc. There are also conditions under which these operations can be executed (xxx_enabled) and the state of the system under each operation (state).

2. Test Harness/Steper/adapter: access the system under test and specifically implement the operations (actions) defined in the model.

3. Strategies: During the test running process, after completing an operation (action), which operation should be performed next is determined by this strategy. The simplest strategy can be randomly selected, or you can implement it yourself. Some more complex selection strategy algorithms, such as Zstack's fair scheduling algorithm and scheduling algorithms based on historical test paths.

4. Test Runer: Execute tests and inspections

General steps for model-based testing:

1. Analyze and understand the software under test

Model-based software testing requires a thorough understanding of the software being tested. The work of constructing a model that can be used for testing is mainly to determine the test objects and test characteristics according to the testing purpose, and to establish corresponding models for the relevant attributes of the software under test. Specific work at this stage includes,

Fully understand software requirements specifications and design documents, user manuals and fully communicate with the development team.

1) Identify the users of the software system, enumerate each user's input sequence, and study the possible value range of each input, including legal values, boundary values, illegal values, and expected output. This work often requires tool support.

2) Record input occurrence conditions and response occurrence conditions. The response of a software system refers to the output that can be obtained by the user or the change in the internal state of the software that is visible. Its purpose is to design test cases that elicit specific responses and evaluate test results.

3) Study the input sequence, such as the moment when the input occurs, the conditions for the software system to receive specific input, and the input processing sequence.

4) Understand the internal data exchange and calculation process of the software and generate test data that may find defects.

2. Choose the appropriate test model

Different models are suitable for testing different types of software, so the model needs to be selected according to the characteristics of the software.

1) Understand the available models: Different application fields require different test models. For example, telephone switching systems mostly use state models; the concurrent operation of different components in concurrent software systems is modeled using state charts; Markov chains can perform statistical failure analysis on software. The choice of model also depends on the working characteristics of the software system. For example, state machine models can be used to test long-term running software systems.

2) Select based on model characteristics: Only by fully understanding the model and software system can you choose an appropriate model to test the software. Taking state machines as an example, automata theory can classify state machines and explain what languages ​​different state machines can express, so that different state machine models can be selected according to the functions and characteristics of the application. Since generating test data based on a finite state machine is equivalent to traversing a directed graph, graph theory algorithms can guide the generation of test cases.

3) Influence of personnel, organization and tools: Model-based software testing places certain requirements on the knowledge structure and technical level of testers. If a development organization uses models (such as UML) to complete requirements analysis and system design, it is easier to carry out model-based software testing, because testing based on the system analysis and design model can often directly apply model-based software testing technology, and also Models or model details can be continuously adjusted as testing progresses and facilitate test planning early in the development process. Also choose a specific model based on the testing tools used by the development organization.

3. Construct a test model

Taking testing based on the state machine model as an example to illustrate how to construct a test model. First, the software system state must be abstracted. State abstraction is generally performed based on input and output conditions, and generally includes the following processes:

1) Generate an input sequence and specify the applicable conditions for each input, called input constraints. For example, the off-hook action is only allowed when the phone is not off-hook.

2) For each input, the context that produces different responses must be explained, which is called response constraints. For example, when the phone is off-hook, if the current status is ringing, the call will be made, otherwise it will be a dial tone.

3) Construct the corresponding state machine model based on the input sequence, input constraints and response constraints, as shown in the example below.

4. Generate and execute test cases

The automatic generation of test cases depends on the model used for testing. Taking the finite state machine model as an example, the sequence composed of the markers of the arcs in the traversed path is the test case. When constructing a path that satisfies the test criteria, constraints such as path length limits must be considered, and statistical testing also takes into account migration probabilities. Test cases can be executed after generating a collection of test cases that meet specific test adequacy criteria. Take the state machine model as an example~ First, write a script that simulates each different external stimulus of the software system, called a simulation script. Each simulation script corresponds to a different migration in the model; then collect the test cases Translated into test script. You can also use a test generator to directly generate test scripts by traversing the transitions of the state machine. The execution of test cases is the execution process of test scripts. Scripts are reusable resources, and maintaining test scripts is also part of the testing work.

5. Collect test results for analysis

The model-based software testing method does not solve the problem of test failure identification (Test Oracle) and still requires manual inspection to see whether the output is correct. However, the problem of test failure identification can be partially solved through state verification. The state is an abstraction of internal data and is easier to verify.

In addition, compared with traditional testing, one of the advantages of model-based software testing is that other quality factors of the software, such as reliability, can be analyzed based on the test results.

Evaluation of model-based software testing

1. Advantages of model-based software testing

Model-based software testing greatly improves the level of test automation, partially solves the problem of test failure identification, can analyze test results, is conducive to the reuse of test products, and can apply mature theories and technologies to obtain relatively complete analysis results. Modern software engineering emphasizes incremental and iterative development processes and adopts object-oriented development technology to improve software development quality and speed up software development. Since most specifications of object-oriented software systems are expressed using models, these models contain a large amount of information that can be used for software testing. Therefore, model-based software testing can advance the software testing work to the early stage of the development process, such as early planning of testing work. .

2. Disadvantages of model-based software testing

Model-based software testing has the following disadvantages:

1) Testers need to have a certain theoretical foundation, such as knowledge of state machine theory and random processes. You also need to know how to use relevant tools.

2) A certain amount of initial investment is required, such as model selection, software function division, model construction, etc.

3) Sometimes it is impossible to overcome the inherent defects of the model, such as state explosion, which puts forward requirements for inspection, review and maintenance of the model, and also directly affects test automation. The problem of state explosion is generally solved by reducing the test scale and reducing the difficulty of the test through abstraction and exclusion methods.

Finally: The complete software testing video tutorial below has been compiled and uploaded. Friends who need it can get it by themselves [guaranteed 100% free]

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/132909692