CN112084667A - Test case generation method and device and electronic equipment - Google Patents

Test case generation method and device and electronic equipment Download PDF

Info

Publication number
CN112084667A
CN112084667A CN202010961923.9A CN202010961923A CN112084667A CN 112084667 A CN112084667 A CN 112084667A CN 202010961923 A CN202010961923 A CN 202010961923A CN 112084667 A CN112084667 A CN 112084667A
Authority
CN
China
Prior art keywords
input
data
file
parameter
expected
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010961923.9A
Other languages
Chinese (zh)
Inventor
李京燕
张桥
王宝杰
何子中
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Shi Guan Jin Yang Technology Development Co ltd
Original Assignee
Beijing Shi Guan Jin Yang Technology Development Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Shi Guan Jin Yang Technology Development Co ltd filed Critical Beijing Shi Guan Jin Yang Technology Development Co ltd
Priority to CN202010961923.9A priority Critical patent/CN112084667A/en
Publication of CN112084667A publication Critical patent/CN112084667A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/20Design optimisation, verification or simulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Abstract

The application discloses a test case generation method, a test case generation device and electronic equipment, wherein the method comprises the following steps: obtaining an input file, wherein the input file corresponds to a Functional Model Unit (FMU) model to be tested and at least comprises at least one parameter data, at least one time data and at least one input data; generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time; and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.

Description

Test case generation method and device and electronic equipment
Technical Field
The present application relates to the field of simulation technologies, and in particular, to a method and an apparatus for generating a test case, and an electronic device.
Background
In Functional model Unit FMU (Functional Mock-up Unit) testing, an FMU is typically tested using a large number of test cases.
The FMU model includes a large number of Inputs (Inputs), Outputs (Outputs) and Parameters (Parameters), and the Inputs, Outputs and Parameters are divided into multiple types, so that if the FMU model still depends on a developer to manually design a test case, the FMU model obviously has the defect of low efficiency.
Therefore, a technical solution capable of efficiently generating test cases is needed.
Disclosure of Invention
In view of this, the present application provides a method and an apparatus for generating a test case, and an electronic device, including:
a method for generating a test case, the method comprising:
obtaining an input file, wherein the input file corresponds to a Functional Model Unit (FMU) model to be tested and at least comprises at least one parameter data, at least one time data and at least one input data;
generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time;
and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
The above method, preferably, further comprises:
obtaining an expected file, wherein the expected file corresponds to the FMU model and at least comprises at least one time data and at least one output data;
and generating expected output data according to the expected file, wherein the expected output data comprises at least one output variable, the output variable at least corresponds to an expected value at the operation moment, the expected output data is at least used for generating the test case, and the test case is used for testing the FMU model and obtaining a simulation test result of the FMU model.
Preferably, the method for generating the expected output data according to the expected file includes:
obtaining target output column data according to names of a plurality of file columns contained in the expected file, wherein the target output column data is column data with the same variable name as at least one output variable in the FMU model;
obtaining an expected value corresponding to the output variable at each operation time in the expected file according to the target output column data;
and generating expected output data according to at least the expected value.
The above method, preferably, further comprises:
obtaining tolerance data corresponding to the expected value, wherein the tolerance data represent the difference limit between the corresponding output value of the output variable at the operation moment and the expected value;
wherein generating the desired output data based at least on the desired value comprises:
and generating expected output data according to the expected value and the tolerance data corresponding to the expected value.
Preferably, the method for generating test input data according to the input file includes:
respectively obtaining target parameter column data and target input column data according to the names of a plurality of file columns contained in the input file, wherein the target parameter column data is column data with the same parameter name as at least one simulation parameter in the FMU model, and the target input column data is column data with the same variable name as at least one input variable in the FMU model;
according to the target parameter column data and the target input column data, respectively obtaining a parameter value corresponding to the simulation parameter at least one operation time of the FMU model and an input value corresponding to the input variable at the operation time; the operation time is matched with the simulation step length of the FMU model;
generating test input data based at least on the parameter values and the input values.
Preferably, in the above method, obtaining, according to the target parameter column data and the target input column data, a parameter value of the simulation parameter corresponding to at least one operation time of the FMU model and an input value of the input variable corresponding to the operation time respectively includes:
judging whether the simulation step length is smaller than the time length between two adjacent time data in the input file;
if so, processing the target parameter column data according to a preset first numerical value generation mode to obtain a parameter value corresponding to the simulation parameter at least one operation time of the FMU model, and processing the target input column data according to a preset second numerical value generation mode to obtain an input value corresponding to the input variable at the operation time;
the first numerical value generation mode corresponds to the data type of the target parameter column data, and the second numerical value generation mode corresponds to the data type of the target input column data.
Preferably, before generating the test input data according to the input file, the method further includes:
judging whether the file format of the input file meets a preset input file format or not;
if yes, executing the steps of: generating test input data according to the input file;
and if not, outputting first prompt information, wherein the first prompt information is used for prompting the input file to be modified until the file format of the input file meets the preset input file format.
Preferably, before generating the expected output data according to the expected file, the method further includes:
judging whether the file format of the expected file meets a preset expected file format or not;
if yes, executing the steps of: generating expected output data according to the expected file;
and if not, outputting second prompt information, wherein the second prompt information is used for prompting the modification of the expected file until the file format of the expected file meets the expected file format.
An apparatus for generating test cases, the apparatus comprising:
the FMU model testing device comprises a file obtaining unit, a file analyzing unit and a test result obtaining unit, wherein the file obtaining unit is used for obtaining an input file, the input file corresponds to an FMU model to be tested, and the input file at least comprises at least one parameter data, at least one time data and at least one input data;
the data generating unit is used for generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time;
and the case obtaining unit is used for obtaining a test case of the FMU model at least according to the test input data, and the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
An electronic device, comprising:
a memory for storing an application program and data generated by the application program running;
a processor for executing the application to implement: obtaining an input file, wherein the input file corresponds to an FMU model to be tested, and the input file at least comprises at least one parameter data, at least one time data and at least one input data; generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time; and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
According to the technical scheme, after the input file corresponding to the FMU model to be tested is obtained, the test input data can be generated according to the parameter data, the time data and the input data in the input file, the test input data comprise simulation parameters, operation time and input variables, the simulation parameters and the input variables respectively correspond to values at the operation time, the test case of the FMU model can be obtained on the basis of the values, and the FMU model can perform simulation operation on the test input data in the test case, so that the test of the FMU model is realized. Therefore, the test input data used for carrying out test operation on the FMU model in the test case can be generated by processing the parameter data, the time data and the input data in the input file on the basis of the input file, and the test input data does not need to be manually designed by developers in the process, so that the generation efficiency of the test case can be improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
Fig. 1 is a flowchart of a method for generating a test case according to a first embodiment of the present application;
FIG. 2 is an exemplary diagram of an input file;
fig. 3 is another flowchart of a method for generating a test case according to a first embodiment of the present application;
FIG. 4 is an exemplary diagram of a desired file;
fig. 5 is a partial flowchart of a method for generating a test case according to a first embodiment of the present application;
fig. 6 is another partial flowchart of a method for generating a test case according to a first embodiment of the present application;
fig. 7 and fig. 8 are further flowcharts illustrating a method for generating a test case according to a first embodiment of the present application, respectively;
fig. 9 is a schematic structural diagram of a test case generation apparatus according to a second embodiment of the present application;
fig. 10 is a schematic structural diagram of an electronic device according to a third embodiment of the present application;
FIG. 11 is a schematic flow chart diagram illustrating an embodiment of the present application in a specific implementation;
fig. 12-14 are exemplary diagrams of specific applications of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Fig. 1 is a flowchart illustrating an implementation of a method for generating a test case according to an embodiment of the present application, where the method may be applied to an electronic device capable of data processing, such as a computer or a server. The technical scheme in the embodiment is mainly used for improving the generation efficiency of the test case of the FMU model.
Specifically, the method in this embodiment may include the following steps:
step 101: an input file is obtained.
The input file corresponds to an FMU model to be tested, and the FMU model can be any FMU model where a software platform is located. For example, the modeling software platform converts a simulation model built based on the FMI standard into an FMU file and exports the FMU file, that is, the exported FMU model, and in this embodiment, test cases are mainly generated for FMU models exported by various different software platforms.
Specifically, the input file at least comprises at least one parameter data, at least one time data and at least one input data. The input file may be a table file, and the input file includes a plurality of table data, such as time column data composed of at least one time data, parameter column data composed of at least one parameter data, and input column data composed of at least one input data.
In an implementation manner, the input file in this embodiment may be manually imported, so that the test system implemented in this application can obtain the imported input file;
in another implementation manner, in this embodiment, the input file may be read in the storage area where the input file is located through the import interface, for example, the input file with the same name or a matching name may be searched in the storage area according to the model name of the FMU model, and the input file may be imported, so as to obtain the input file.
It should be noted that the time data in the input file may be one or more, as shown by the time in the time column in fig. 2, and the unit is second; the parameter data may include the corresponding parameter values of one or more simulation parameters at each time, as shown in the parameter values in the real _ tunable _ param column in fig. 2; the input data may contain corresponding input values of one or more input variables at each time data, as shown by the input values in the real _ continuous _ in column, the real _ discrete _ in column, the int _ in column, and the cool _ in column in fig. 2.
It should be noted that the input file further includes simulation duration, such as 2 minutes or 5 seconds. The simulation time length value can be modified through an interactive interface.
Step 102: and generating test input data according to the input file.
The test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, wherein the simulation parameter corresponds to a parameter value at each operation time, and the input variable corresponds to an input value at each operation time.
Specifically, the operation time in the test input data is matched with the operation step length of the FMU model, and if the operation step length of the FMU model is 0.1 second, the operation time in the test input data is: starting from an initial preset time such as 0, each subsequent operation time is sequentially increased by 0.1 second, such as: 0. 0.1, 0.2, 0.3, etc.; if the operation step length of the FMU model is 0.5 second, the operation time in the test input data is as follows: starting from an initial preset time such as 0, each subsequent operation time is sequentially increased by 0.5 seconds, such as: 0. 0.5, 1, 1.5, etc.
The number and the type of the simulation parameters in the test input data correspond to the number and the type of the simulation parameters in the parameter data in the input file, and the parameter value of each simulation parameter in the test input data at each operation time can be determined according to the parameter data in the input file, for example, the parameter values of a certain simulation parameter in the input file at the operation times of 0, 0.1, 0.2, 0.3 and the like are read as the parameter values of the simulation parameter in the test input data at the corresponding operation time.
The number and kind of input variables in the test input data correspond to the number and kind of input variables in the input data in the input file, and the input value of each input variable in the test input data at each operation time can be determined from the input data in the input file. For example, the input values of a certain input variable in the input file at the operation times of 0, 0.1, 0.2, 0.3, etc. are read as the input values of the input variable in the test input data at the corresponding operation time.
The simulation parameters herein refer to variable parameters in the FMU model, and the simulation parameters vary in the simulation calculation at each simulation time.
Step 103: and obtaining a test case of the FMU model at least according to the test input data.
In this embodiment, the test input data may be processed by a name or a label, so as to obtain a test case, where the test case is at least used to test the FMU model and obtain a simulation operation result of the FMU. For example, when the FMU model performs test operation on a test case, the FMU model sequentially operates input values of input variables at each operation time based on parameter values of simulation parameters, thereby obtaining a simulation operation result of the FMU model, where the simulation operation result includes output values corresponding to one or more output variables of the FMU model at each operation time.
According to the scheme, in the test case generation method provided by the embodiment of the application, after the input file corresponding to the to-be-tested FMU model is obtained, test input data can be generated according to parameter data, time data and input data in the input file, the test input data comprises simulation parameters, operation time and input variables, the simulation parameters and the input variables respectively correspond to values at the operation time, and therefore the test case of the FMU model can be obtained, the FMU model can perform simulation operation on the test input data in the test case, and testing of the FMU model is achieved. Therefore, in the embodiment, the parameter data, the time data and the input data in the input file can be processed on the basis of the input file to generate the test input data for performing the test operation on the FMU model in the test case, and in the process, a developer does not need to design manually, so that the generation efficiency of the test case can be improved.
In an implementation manner, the test case generated in this embodiment includes, in addition to test input data, expected output data, where the expected output data can be used to perform test judgment on a simulation operation result of the FMU model to obtain a simulation test result of the FMU model, and the simulation test result can represent whether a function of the FMU model is normal.
Specifically, the present embodiment may further include the following steps, as shown in fig. 3:
step 104: a desired file is obtained.
The expected file corresponds to the FMU model, and at least one time data and at least one output data are contained in the expected file. Based on this, in a specific implementation, the desired file may be a table file, and a plurality of table data, such as time column data composed of at least one time data and output column data composed of at least one output data, is contained in the desired file.
In one implementation, the expected file in this embodiment may be imported manually, so that the test system implemented in this application can obtain the imported expected file;
in another implementation manner, in this embodiment, the desired file may be read in the storage area where the desired file is located through the import interface, for example, the desired file having the same name or a matching name may be searched in the storage area according to the model name of the FMU model, and the desired file may be obtained by importing the desired file.
It should be noted that the time data in the expected file may be one or more, as shown by the time in the time column in fig. 4, and the unit is second; the output data may be output values containing one or more output variables corresponding to the data at each time, as shown by the output values in the real _ continuous _ out column, the real _ discrete _ out column, the int _ out column, and the pool _ out column shown in fig. 4.
Step 105: desired output data is generated from the desired file.
The expected output data comprises at least one output variable, the output variable at least corresponds to an expected value at the operation time, and the expected value refers to an ideal value output by the output variable at the corresponding operation time under the condition that the FMU model is normal in function.
It should be noted that the number of operation times in the expected output data may not be completely consistent with the operation times in the test input data, because the operation times in the expected output data are times at which the comparison between the output value and the corresponding expected value is required, and the operation times in the test input data are times at which the FMU model needs to perform one simulation operation, so the operation times in the expected output data may be completely consistent with the operation times in the test input data to represent that the comparison between the output value and the expected value at each operation time is required, or the operation times in the expected output data are a part of the operation times in the test input data to represent that the comparison between the output value and the expected value at part of the operation times is required.
Based on this, in the annotation 103 in this embodiment, when obtaining the test case of the FMU model according to the test input data, the expected output data and the test input data may be combined together to generate the test case of the FMU model, and based on this, the generated test case may be used to test the FMU model and obtain the simulation test result of the FMU model. For example, the FMU model sequentially operates the input values of the input variables at each operation time based on the parameter values of the simulation parameters to obtain a simulation operation result of the FMU model, and then obtains a simulation test result of the FMU model according to the output value of the output variable at each operation time in the simulation output result and the expected value of the output variable at each operation time in the expected output data, wherein the simulation test result can represent whether the FMU model functions normally or not.
Specifically, when generating the desired output data in step 105, the following may be implemented, as shown in fig. 5:
step 501: and obtaining target output column data according to the names of a plurality of file columns contained in the expected file.
The target output column data is column data having the same variable name as at least one output variable in the FMU model, and one or more target output column data respectively correspond to each output variable.
Specifically, in this embodiment, according to the output variable to be tested in the FMU model, the column data with the same variable name may be obtained in a plurality of file columns included in the expected file.
For example, output variables real _ continuous _ out, real _ discrete _ out, int _ out, and pool _ out to be tested in the FMU model are obtained from the desired file according to the variable names, i.e., the column data of real _ continuous _ out column, real _ discrete _ out column, int _ out column, and pool _ out column, i.e., the target output column data.
Step 502: and obtaining the expected value corresponding to the output variable at each operation time in the expected file according to the target output column data.
In this embodiment, after the target output line data is read, each expected value in the target output line data is read, so that the expected value corresponding to the output variable corresponding to the line at each operation time in the expected file can be obtained.
Step 503: desired output data is generated based at least on the desired values.
Specifically, in the present embodiment, the expected output data is generated directly from the expected values of the output variables corresponding to each operation time in the expected file.
Alternatively, in this embodiment, the tolerance data corresponding to the expected value may be obtained first, and then the expected output data may be generated according to the expected value and the tolerance data corresponding to the expected value.
The tolerance data represents the difference limit between the output value corresponding to the output variable at the operation time and the expected value, and means that: the degree of difference between the allowed output value and the expected value in the case where the FMU model functions normally.
In a specific implementation, the tolerance data may include a deviation calculation manner and a deviation threshold corresponding to the deviation calculation manner, and the deviation calculation manner and the deviation threshold correspond to the variable type of the output variable.
For example, for a continuous output variable, the corresponding tolerance data includes a relative difference calculation manner or an absolute difference calculation manner, and the corresponding deviation threshold is a threshold corresponding to a relative difference or an absolute difference between an output value corresponding to the output variable and an expected value, for example, when the relative difference between the output value corresponding to the output variable in the simulation operation result and the corresponding expected value in the expected output data is greater than the deviation threshold at the same operation time, the obtained simulation test result represents that the FMU model is not functioning normally;
for discrete output variables, the corresponding tolerance data includes a time tolerance calculation mode, and correspondingly, the deviation threshold is a threshold corresponding to a time difference value corresponding to an output value corresponding to the output variable and an operation time with different expected values, for example, when a time difference value formed by the output value corresponding to the output variable in the simulation operation result and a target operation time with different expected values in the expected output data is greater than the deviation threshold, the obtained simulation test result represents that the FMU model is abnormal in function; or the obtained simulation test result represents that the FMU model is abnormal in function under the condition that the target operation time is larger than the deviation threshold and is not connected with the operation time with the same output value and expected value.
In one implementation, when generating the test input data in step 102, the following may be specifically implemented, as shown in fig. 6:
step 601: and respectively obtaining target parameter column data and target input column data according to the names of a plurality of file columns contained in the input file.
The target parameter column data is column data which has the same parameter name as at least one simulation parameter in the FMU model, and can be one or more, and corresponds to each simulation parameter respectively; the target input column data is column data having the same variable name as at least one input variable in the FMU model, and may be one or more, respectively corresponding to each input variable.
Specifically, in this embodiment, column data having the same parameter name and variable name may be acquired in a plurality of file columns included in the input file according to the simulation parameter and the input variable in the FMU model.
For example, the FMU model includes a simulation parameter real _ tunable _ param and input variables real _ continuous _ in, real _ discrete _ in, int _ in, and pool _ in, and column data of the real _ tunable _ param column, the real _ continuous _ in column, the real _ discrete _ in column, the int _ in column, and the pool _ in column, that is, target parameter column data and target input column data, are acquired in the input file according to the parameter names and the variable names.
Step 602: and respectively obtaining a parameter value corresponding to the simulation parameter at least one operation moment of the FMU model and an input value corresponding to the input variable at the operation moment according to the target parameter column data and the target input column data.
And the operation time corresponding to the parameter value and the input value is matched with the simulation step length of the FMU model. In this embodiment, after the target parameter column data is read, each parameter value in the target parameter column data is read, so as to obtain a parameter value corresponding to the simulation parameter in the column at each operation time of the FMU model; after the target input column data is read, each input value in the target input column data is read, and the corresponding input value of the input variable corresponding to the column at each operation time of the FMU model can be obtained.
It should be noted that, because the time data in the input file or the operation time in the target parameter column data and the target input column data may not match the simulation step size of the FMU model, for example, the time interval, i.e., the time length, between two adjacent time data in the input file may be smaller than or greater than or equal to the simulation step size, when obtaining the input value corresponding to the parameter value and the input variable corresponding to the input variable at the operation time of the simulation parameter at least one operation time of the FMU model, a special manner needs to be adopted to implement, which is specifically as follows:
firstly, judging whether the simulation step length is smaller than the time length between two adjacent moment data in an input file;
if the simulation step length is equal to the time length between two adjacent time data in the input file, the time data in the input file is matched with the operation time of the FMU model, at the moment, the value reading of each parameter data in the target parameter column data can be directly carried out to be used as the corresponding parameter value of the simulation parameter at the corresponding operation time, and the value reading of each input data in the target input column data is carried out to be used as the corresponding input value of the input variable at the corresponding operation time;
if the simulation step length is longer than the time between two adjacent time data in the input file, reading the parameter value and the input value corresponding to the corresponding operation time in the target parameter column data and the target input column data according to the operation time in the FMU model;
if the simulation step length is less than the time length between two adjacent time data in the input file, one or more times need to be inserted between the two time data of the input file, and a numerical value is generated according to the inserted time, that is: processing the target parameter column data according to a preset first numerical value generation mode to obtain a corresponding parameter value of the simulation parameter at least one operation moment of the FMU model; and processing the target input column data according to a preset second value generation mode to obtain an input value corresponding to the input variable at least one operation moment of the FMU model.
The first numerical value generation mode corresponds to the data type of the target parameter column data, the second numerical value generation mode corresponds to the data type of the target input column data, and the first numerical value generation mode and the second numerical value generation mode are the same generation mode under the condition that the data type of the target parameter column data is the same as the data type of the target input column data.
Specifically, the first numerical value generation method is a linear interpolation numerical value generation method when the target parameter column data is of a continuous data type, and the second numerical value generation method is a linear interpolation numerical value generation method when the target input column data is of a continuous data type. For example, taking the input file shown in fig. 2 as an example, the time data in the input file are 0, 0.5, 1, 1.5, 2, etc., respectively, and the input values of the continuous input variable real _ continuous _ in are: 0.2, 1, etc., and the operation time of the FMU model is: 0. 0.1, 0.2, 0.3, 0.4, 0.5, etc., for the continuous input variable real _ continuous _ in, the input value at the operation time 0 is the input value of the time data 0, the input value at the operation time 0.5 is the input value of the time data 0.5, and for the input values at the operation times 0.1, 0.2, 0.3, 0.4 between the operation time 0 and the operation time 0.5, the interpolation is performed at the operation times 0.1, 0.2, 0.3, 0.4 by a numerical value generation method of linear interpolation: 0.4, 0.8, 1.2 and 1.6, and obtaining the input value of the continuous input variable real _ continuous _ in at each operation time by the row pushing;
under the condition that the target parameter line data is of a discrete data type, a first numerical value generation mode is a numerical value generation mode for maintaining numerical values; in the case where the target input line data is of a discrete data type, the second numerical value generation method is a numerical value generation method in which numerical values are held.
For example, the time data in the input file are 0, 0.5, 1, 1.5 and 2, and so on, respectively, and the input values of the discrete input variables are: 0.1, 0, etc., and the operation time of the FMU model is: 0. 0.1, 0.2, 0.3, 0.4, 0.5, etc., for discrete input variables, the input value at operation time 0 is the input value 0 of time data 0, the input value at operation time 0.5 is the input value 1 of time data 0.5, the input value at operation time 1 is the input value 0 of time data 1, and for operation times 0.1, 0.2, 0.3, 0.4 between operation time 0 and operation time 0.5, numerical value generation is adopted by numerical value holding, numerical values are set at operation times 0.1, 0.2, 0.3, 0.4: 0. 0, and a numerical value generation method of numerical value holding is adopted for input values of operation time 0.6, 0.7, 0.8, 0.9 between operation time 0.5 and operation time 1, and numerical values are set at operation time 0.6, 0.7, 0.8, 0.9: 1. 1, and obtaining the input value of the discrete input variable at each operation time by the column deduction.
Step 603: test input data is generated based on at least the parameter values and the input values.
Specifically, in this embodiment, the combination may be directly performed according to the parameter values and the input values, and the parameter values of the simulation parameters and the input values of the input variables are respectively corresponding to each operation time of the FMU model, so as to obtain the test input data.
In one implementation, before step 102, the method in this embodiment may further include the following steps, as shown in fig. 7:
step 106: and judging whether the file format of the input file meets the preset input file format or not.
Specifically, in this embodiment, the step of determining whether the file format of the input file meets the preset input file format may be: and judging whether the file attribute of the input file, the format of each file column in the input file, the data attribute of each file column and the like are consistent with the preset file attribute, column format and data attribute.
If yes, executing step 102 and step 103, generating test input data according to the input file, and generating a test case according to the test input data or combining expected output data on the basis of the test input data for performing test operation on the FMU model.
And if not, step 107 is performed.
Step 107: and outputting the first prompt message.
The first prompt information is used for prompting the input file to be modified until the file format of the input file meets the preset input file format.
Specifically, the first prompt message may include a file name of the input file to be modified, and may further include a name of a file column or a name of a file row of the input file to be modified, so as to prompt the user to modify the input file.
In one implementation, before step 105, the method in this embodiment may further include the following steps, as shown in fig. 8:
step 108: and judging whether the file format of the expected file meets a preset expected file format or not.
Specifically, in this embodiment, the step of determining whether the file format of the expected file meets the preset expected file format may be: and judging whether the file attribute of the expected file, the format of each file column in the expected file, the data attribute of each file column and the like are consistent with the preset file attribute, column format and data attribute.
If yes, executing step 105 and step 103, generating expected output data according to the expected file, and generating a test case according to the test input data and the expected output data for performing test operation on the FMU model.
And if not, step 109 is performed.
Step 109: and outputting the second prompt message.
The second prompt information is used for prompting the modification of the expected file until the file format of the expected file meets the preset expected file format.
Specifically, the second prompt message may include a file name of a desired file that needs to be modified, and may further include a name of a file column or a name of a file row of the desired file that needs to be modified, and so on, to prompt the user to modify the desired file.
Referring to fig. 9, a schematic structural diagram of a test case generation apparatus according to a second embodiment of the present disclosure is provided, where the apparatus may be applied to an electronic device capable of performing data processing, such as a computer or a server. The technical scheme in the embodiment is mainly used for improving the generation efficiency of the test case of the FMU model.
Specifically, the apparatus in this embodiment may include the following units:
a file obtaining unit 901, configured to obtain an input file, where the input file corresponds to an FMU model to be tested, and the input file at least includes at least one parameter data, at least one time data, and at least one input data;
a data generating unit 902, configured to generate test input data according to the input file, where the test input data at least includes at least one simulation parameter, at least one operation time, and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time;
a case obtaining unit 903, configured to obtain a test case of the FMU model at least according to the test input data, where the test case is at least used to test the FMU model and obtain a simulation operation result of the FMU.
According to the second embodiment of the present invention, after the input file corresponding to the FMU model to be tested is obtained, the test input data can be generated according to the parameter data, the time data and the input data in the input file, where the test input data includes the simulation parameter, the operation time and the input variable, and the simulation parameter and the input variable respectively correspond to values at the operation time, so that the test case of the FMU model can be obtained, and the FMU model can perform simulation operation on the test input data in the test case, thereby implementing the test on the FMU model. Therefore, the test input data used for carrying out test operation on the FMU model in the test case can be generated by processing the parameter data, the time data and the input data in the input file on the basis of the input file, and the test input data does not need to be manually designed by developers in the process, so that the generation efficiency of the test case can be improved.
In one implementation, the file obtaining unit 901 is further configured to: obtaining an expected file, wherein the expected file corresponds to the FMU model and at least comprises at least one time data and at least one output data;
the data generation unit 902 is further configured to: and generating expected output data according to the expected file, wherein the expected output data comprises at least one output variable, the output variable at least corresponds to an expected value at the operation moment, the expected output data is at least used for generating the test case, and the test case is used for testing the FMU model and obtaining a simulation test result of the FMU model.
Specifically, when the data generating unit 902 generates the expected output data according to the expected file, it is specifically configured to: obtaining target output column data according to names of a plurality of file columns contained in the expected file, wherein the target output column data is column data with the same variable name as at least one output variable in the FMU model; obtaining an expected value corresponding to the output variable at each operation time in the expected file according to the target output column data; and generating expected output data according to at least the expected value.
In one implementation, the data generation unit 902 is further configured to: obtaining tolerance data corresponding to the expected value, wherein the tolerance data represent the difference limit between the corresponding output value of the output variable at the operation moment and the expected value;
when the data generating unit 902 generates the expected output data at least according to the expected value, it is specifically configured to: and generating expected output data according to the expected value and the tolerance data corresponding to the expected value.
In an implementation manner, when the data generating unit 902 generates the test input data according to the input file, specifically, the data generating unit is configured to:
respectively obtaining target parameter column data and target input column data according to the names of a plurality of file columns contained in the input file, wherein the target parameter column data is column data with the same parameter name as at least one simulation parameter in the FMU model, and the target input column data is column data with the same variable name as at least one input variable in the FMU model; according to the target parameter column data and the target input column data, respectively obtaining a parameter value corresponding to the simulation parameter at least one operation time of the FMU model and an input value corresponding to the input variable at the operation time; the operation time is matched with the simulation step length of the FMU model; generating test input data based at least on the parameter values and the input values.
Specifically, the data generating unit 902 first determines whether the simulation step is smaller than the time length between two adjacent time data in the input file;
if so, processing the target parameter column data according to a preset first numerical value generation mode to obtain a parameter value corresponding to the simulation parameter at least one operation time of the FMU model, and processing the target input column data according to a preset second numerical value generation mode to obtain an input value corresponding to the input variable at the operation time;
the first numerical value generation mode corresponds to the data type of the target parameter column data, and the second numerical value generation mode corresponds to the data type of the target input column data.
In one implementation, the data generating unit 902 is further configured to generate the test input data according to the input file; judging whether the file format of the input file meets a preset input file format or not; if so, executing: generating test input data according to the input file; and if not, outputting first prompt information, wherein the first prompt information is used for prompting the input file to be modified until the file format of the input file meets the preset input file format.
In one implementation, before generating the desired output data according to the desired file, the data generating unit 902 is further configured to: judging whether the file format of the expected file meets a preset expected file format or not; if so, executing: generating expected output data according to the expected file; and if not, outputting second prompt information, wherein the second prompt information is used for prompting the modification of the expected file until the file format of the expected file meets the expected file format.
It should be noted that, for the specific implementation of each unit in the present embodiment, reference may be made to the corresponding content in the foregoing, and details are not described here.
Referring to fig. 10, a schematic structural diagram of an electronic device according to a third embodiment of the present application is provided, where the electronic device may be an electronic device capable of performing data processing, such as a computer or a server. The technical scheme in the embodiment is mainly used for improving the generation efficiency of the test case of the FMU model.
Specifically, the electronic device in this embodiment may include the following structure:
a memory 1001 for storing an application program and data generated by the operation of the application program;
a processor 1002 for executing the application to implement: obtaining an input file, wherein the input file corresponds to an FMU model to be tested, and the input file at least comprises at least one parameter data, at least one time data and at least one input data; generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time; and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
According to the technical scheme, after the input file corresponding to the FMU model to be tested is obtained, the electronic device according to the third embodiment of the application can generate the test input data according to the parameter data, the time data and the input data in the input file, the test input data comprise the simulation parameters, the operation time and the input variables, the simulation parameters and the input variables respectively correspond to values at the operation time, based on the values, the test case of the FMU model can be obtained, and the FMU model can perform simulation operation on the test input data in the test case, so that the test of the FMU model is realized. Therefore, the test input data used for carrying out test operation on the FMU model in the test case can be generated by processing the parameter data, the time data and the input data in the input file on the basis of the input file, and the test input data does not need to be manually designed by developers in the process, so that the generation efficiency of the test case can be improved.
It should be noted that, the specific implementation of the processor in the present embodiment may refer to the corresponding content in the foregoing, and is not described in detail here.
The following describes the technical solution of the present application with reference to the flowchart shown in fig. 11:
firstly, importing an input file and a reference file of a simulation result, namely an expected file in the foregoing;
the format of the input file is shown in fig. 2, the first column is time in seconds, and the remaining columns are parameter data corresponding to the simulation parameters or input data corresponding to the input variables;
secondly, analyzing the input file, judging whether the input file conforms to the format of the input file, if so, continuing to execute, and if not, prompting to modify the input file until the input file conforms to the format of the input file;
then, in the case that the input file meets the file format, automatically associating the simulation parameters and the input variables, for example, searching whether the FMU to be tested has the parameters and variables with the same name according to the file column name, if the names are the same (the characters are the same or contain single quotation marks, and the double quotation marks are all regarded as the same, such as "int _ in" is equal to int _ in), associating the column data with the parameters or the input variables of the FMU, and using the column data as the input value during simulation. As shown in fig. 12, before the input file is not imported, neither the simulation parameters nor the input variables of the FMU model have corresponding values in the test input data; as shown in fig. 13, after importing the input file, the simulation parameters and input variables of the FMU model are automatically associated with column data of the same name column in the test input data.
And then, automatically matching the simulation time according to the type matching algorithm of the simulation parameters and the input file, wherein the time interval in the input file is less than the simulation step length of the FMU model, and automatically associating the numerical value generation algorithm (mode) of the simulation parameters and the input variables. For example, the continuous input variables (real _ continuous _ in, etc. are continuous) and the simulation parameters (real _ tunable _ param is variable linear parameters) use a linear interpolation algorithm, and the values of the discrete input variables and the simulation parameters use a numerical holding algorithm (mode).
Taking the input file in fig. 2 as an example, assuming that the simulation step size is 0.1 second, after linear interpolation processing is performed on the continuous real _ continuous _ in, as shown in fig. 14, an input value of the input variable at each operation time is obtained.
In addition, the simulation duration of the FMU model can be set according to the input file.
Then, analyzing the reference file and judging whether the reference file conforms to the reference file format, namely the expected file format in the previous text, if the reference file conforms to the reference file format, continuing to execute, and if the reference file does not conform to the reference file format, prompting to modify the reference file until the reference file conforms to the reference file format;
the output variables are then automatically correlated, such as by automatically matching the output variables according to the data column name. The reference file format is as shown in fig. 4, and as with the input file format, the first column of time and the remaining columns of parameter output values are used to obtain the expected output data;
and finally, generating a test case according to the test input data obtained by the input file and the expected output data obtained by the reference file.
Therefore, in the embodiment, the test case can be automatically generated according to the test data such as the input file and the expected file, specifically, the generation of the test input data in the test case can be realized by automatically matching the corresponding numerical value generation algorithm according to the input of the FMU and the type of the parameter, and the expected output data can be automatically matched according to the output of the FMU, so that the output of the test case is completed, the manual writing by developers is not needed, and the test case can be used for carrying out the test operation on the FMU model.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method for generating a test case is characterized in that the method comprises the following steps:
obtaining an input file, wherein the input file corresponds to a Functional Model Unit (FMU) model to be tested and at least comprises at least one parameter data, at least one time data and at least one input data;
generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time;
and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
2. The method of claim 1, further comprising:
obtaining an expected file, wherein the expected file corresponds to the FMU model and at least comprises at least one time data and at least one output data;
and generating expected output data according to the expected file, wherein the expected output data comprises at least one output variable, the output variable at least corresponds to an expected value at the operation moment, the expected output data is at least used for generating the test case, and the test case is used for testing the FMU model and obtaining a simulation test result of the FMU model.
3. The method of claim 2, wherein generating desired output data from the desired file comprises:
obtaining target output column data according to names of a plurality of file columns contained in the expected file, wherein the target output column data is column data with the same variable name as at least one output variable in the FMU model;
obtaining an expected value corresponding to the output variable at each operation time in the expected file according to the target output column data;
and generating expected output data according to at least the expected value.
4. The method of claim 3, further comprising:
obtaining tolerance data corresponding to the expected value, wherein the tolerance data represent the difference limit between the corresponding output value of the output variable at the operation moment and the expected value;
wherein generating the desired output data based at least on the desired value comprises:
and generating expected output data according to the expected value and the tolerance data corresponding to the expected value.
5. The method of claim 1, wherein generating test input data from the input file comprises:
respectively obtaining target parameter column data and target input column data according to the names of a plurality of file columns contained in the input file, wherein the target parameter column data is column data with the same parameter name as at least one simulation parameter in the FMU model, and the target input column data is column data with the same variable name as at least one input variable in the FMU model;
according to the target parameter column data and the target input column data, respectively obtaining a parameter value corresponding to the simulation parameter at least one operation time of the FMU model and an input value corresponding to the input variable at the operation time; the operation time is matched with the simulation step length of the FMU model;
generating test input data based at least on the parameter values and the input values.
6. The method of claim 5, wherein obtaining the parameter value corresponding to the simulation parameter at the operation time of the FMU model and the input value corresponding to the input variable at the operation time according to the target parameter column data and the target input column data respectively comprises:
judging whether the simulation step length is smaller than the time length between two adjacent time data in the input file;
if so, processing the target parameter column data according to a preset first numerical value generation mode to obtain a parameter value corresponding to the simulation parameter at least one operation time of the FMU model, and processing the target input column data according to a preset second numerical value generation mode to obtain an input value corresponding to the input variable at the operation time;
the first numerical value generation mode corresponds to the data type of the target parameter column data, and the second numerical value generation mode corresponds to the data type of the target input column data.
7. The method of claim 1, prior to generating test input data from the input file, the method further comprising:
judging whether the file format of the input file meets a preset input file format or not;
if yes, executing the steps of: generating test input data according to the input file;
and if not, outputting first prompt information, wherein the first prompt information is used for prompting the input file to be modified until the file format of the input file meets the preset input file format.
8. The method of claim 2, wherein prior to generating desired output data from the desired file, the method further comprises:
judging whether the file format of the expected file meets a preset expected file format or not;
if yes, executing the steps of: generating expected output data according to the expected file;
and if not, outputting second prompt information, wherein the second prompt information is used for prompting the modification of the expected file until the file format of the expected file meets the expected file format.
9. An apparatus for generating a test case, the apparatus comprising:
the FMU model testing device comprises a file obtaining unit, a file analyzing unit and a test result obtaining unit, wherein the file obtaining unit is used for obtaining an input file, the input file corresponds to an FMU model to be tested, and the input file at least comprises at least one parameter data, at least one time data and at least one input data;
the data generating unit is used for generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time;
and the case obtaining unit is used for obtaining a test case of the FMU model at least according to the test input data, and the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
10. An electronic device, comprising:
a memory for storing an application program and data generated by the application program running;
a processor for executing the application to implement: obtaining an input file, wherein the input file corresponds to an FMU model to be tested, and the input file at least comprises at least one parameter data, at least one time data and at least one input data; generating test input data according to the input file, wherein the test input data at least comprises at least one simulation parameter, at least one operation time and at least one input variable, the simulation parameter corresponds to a parameter value at the operation time, and the input variable corresponds to an input value at the operation time; and obtaining a test case of the FMU model at least according to the test input data, wherein the test case is at least used for testing the FMU model and obtaining a simulation operation result of the FMU.
CN202010961923.9A 2020-09-14 2020-09-14 Test case generation method and device and electronic equipment Pending CN112084667A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010961923.9A CN112084667A (en) 2020-09-14 2020-09-14 Test case generation method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010961923.9A CN112084667A (en) 2020-09-14 2020-09-14 Test case generation method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN112084667A true CN112084667A (en) 2020-12-15

Family

ID=73737010

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010961923.9A Pending CN112084667A (en) 2020-09-14 2020-09-14 Test case generation method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN112084667A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114546510A (en) * 2022-04-25 2022-05-27 芯天下技术股份有限公司 Verification method and device for suspend function, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003044518A (en) * 2001-07-31 2003-02-14 Yamatake Corp Data processing program, data processing system, and data processing method
CN106201891A (en) * 2016-07-19 2016-12-07 意昂神州(北京)科技有限公司 A kind of model automatization method of testing and device
CN106251017A (en) * 2016-08-02 2016-12-21 北京百度网讯科技有限公司 Data predication method and device
US20200210895A1 (en) * 2018-12-31 2020-07-02 Electronics And Telecommunications Research Institute Time series data processing device and operating method thereof
CN111551988A (en) * 2020-04-23 2020-08-18 中国地质大学(武汉) Seismic data anti-alias interpolation method combining deep learning and prediction filtering
US20200272625A1 (en) * 2019-02-22 2020-08-27 National Geographic Society Platform and method for evaluating, exploring, monitoring and predicting the status of regions of the planet through time

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003044518A (en) * 2001-07-31 2003-02-14 Yamatake Corp Data processing program, data processing system, and data processing method
CN106201891A (en) * 2016-07-19 2016-12-07 意昂神州(北京)科技有限公司 A kind of model automatization method of testing and device
CN106251017A (en) * 2016-08-02 2016-12-21 北京百度网讯科技有限公司 Data predication method and device
US20200210895A1 (en) * 2018-12-31 2020-07-02 Electronics And Telecommunications Research Institute Time series data processing device and operating method thereof
US20200272625A1 (en) * 2019-02-22 2020-08-27 National Geographic Society Platform and method for evaluating, exploring, monitoring and predicting the status of regions of the planet through time
CN111551988A (en) * 2020-04-23 2020-08-18 中国地质大学(武汉) Seismic data anti-alias interpolation method combining deep learning and prediction filtering

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114546510A (en) * 2022-04-25 2022-05-27 芯天下技术股份有限公司 Verification method and device for suspend function, electronic equipment and storage medium
CN114546510B (en) * 2022-04-25 2022-07-08 芯天下技术股份有限公司 Verification method and device for suspend function, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111666746B (en) Conference summary generation method and device, electronic equipment and storage medium
KR101719278B1 (en) Deep learnig framework and image recognition method for content-based visual image recognition
CN110599838A (en) Mathematics automatic question setting method and device
CN112084668A (en) Simulation test method and device and electronic equipment
CN111679979A (en) Destructive testing method and device
CN111198809A (en) Interface automation test method and device
CN107797805B (en) Code packaging method and device and computer readable storage medium
CN112084667A (en) Test case generation method and device and electronic equipment
CN113934834A (en) Question matching method, device, equipment and storage medium
CN111143228B (en) Test code generation method and device based on decision table method
CN109491919B (en) Software testing method and testing platform
CN112052157A (en) Test message construction method, device and system
CN111459483B (en) Interface processing method and device
CN114691903A (en) Intelligent course testing method and system, electronic equipment and storage medium
CN110928790B (en) Test case construction method and device and test equipment
CN113312902A (en) Intelligent auditing and checking method and device for same text
CN108460077B (en) Index analysis method, system and computer readable storage medium
CN111026876A (en) Mnemonic word generation method, public and private key pair generation method, equipment and storage medium
CN112084734A (en) Test result processing method and device and electronic equipment
CN110674628A (en) File template generation method and system
CN114385511A (en) Test data generation method and device, electronic equipment and storage medium
CN113792422B (en) Digital twinning-based TPM equipment management virtual verification method and system
CN111176763B (en) Method and device for calling help function of command
CN116795725B (en) Automatic library checking method and system of clinical electronic data acquisition system
CN111427873B (en) Data cleaning method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination