CN115470147A - Unit testing method and device - Google Patents

Unit testing method and device Download PDF

Info

Publication number
CN115470147A
CN115470147A CN202211278548.3A CN202211278548A CN115470147A CN 115470147 A CN115470147 A CN 115470147A CN 202211278548 A CN202211278548 A CN 202211278548A CN 115470147 A CN115470147 A CN 115470147A
Authority
CN
China
Prior art keywords
test case
test
target field
unit
variable
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
CN202211278548.3A
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.)
Agricultural Bank of China
Original Assignee
Agricultural Bank of China
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 Agricultural Bank of China filed Critical Agricultural Bank of China
Priority to CN202211278548.3A priority Critical patent/CN115470147A/en
Publication of CN115470147A publication Critical patent/CN115470147A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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
    • 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/3688Test management for test execution, e.g. scheduling of test suites
    • 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/3692Test management for test results analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a unit test method and a unit test device, wherein a test case comprising bottoming data, a test object and assertion is constructed in advance according to a preset variable rule, before the test case is executed, the value format of a primary key field conforming to the preset variable rule is obtained by analyzing the test case, a character string is randomly generated according to the value format of the primary key field and used as the value of the primary key field, and the test case after instantiation of the primary key value is obtained. The primary key values meeting the preset variable rule are randomly generated every time the unit test is executed, the bottoming data, the test objects and the asserted primary key values of all the reference primary keys in the same test case in the same unit test are consistent, the primary key values of the same test case in different unit tests are different, the problem of unit test failure caused by primary key collision is avoided in concurrent execution, and the unit test efficiency is effectively improved.

Description

Unit testing method and device
Technical Field
The invention relates to the field of testing, in particular to a unit testing method and a unit testing device.
Background
The unit test is an important ring in the software development process, the minimum testable unit in the software is checked and verified, and the unit test is a means for a developer to actively find a code problem and realize automatic autonomous test. The unit test does not force to depend on data and functions except the unit module, and can be executed independently and repeatedly without limit.
Currently, a unit test has a situation that the same test case is executed for multiple times at the same time. For example, in the case of multiple local developers, the local of different developers simultaneously perform the full-scale unit test; or the local development unit test and the remote pipeline simultaneously execute the unit test; or multiple remote pipelines simultaneously perform unit testing. In the above concurrent case, if the parameterized data of the test is fixed constant data, when the same data is concurrently written, a problem may occur in which the unit test executed after concurrency fails due to a primary key conflict, and when the same record is concurrently updated or deleted, the unit test executed concurrently may also fail.
Disclosure of Invention
In view of this, the present invention provides a unit testing method and apparatus, which avoid the problem of unit testing failure caused by a primary key conflict in concurrent execution, and effectively improve unit testing efficiency.
In order to achieve the above purpose, the invention provides the following specific technical scheme:
a unit testing method, comprising:
obtaining a test case which is constructed in advance according to a preset variable rule, wherein the test case comprises: backing data, test objects and assertions;
analyzing the test case to obtain the value format of each target field which accords with the preset variable rule, wherein the target field comprises a main key field;
respectively randomly generating character strings according to the value format of each target field, and using the character strings as the values of the corresponding target fields to realize instantiation of the test case;
and executing the instantiated test case.
Optionally, the method for constructing the test case includes:
determining each target field and non-target field including a main key field in bottoming data, a test object and assertion in a test case;
respectively generating a value format of each target field according to the preset variable rule and the variable name, the variable type and the variable length of each target field;
and generating the value of the non-target field according to the unit test requirement.
Optionally, analyzing the test case to obtain a value format of each target field meeting the preset variable rule, including:
scanning the test case, and extracting each target field with a value format conforming to the preset variable rule;
and respectively analyzing the value format of each target field to obtain the variable name, the variable type and the variable length of each target field.
Optionally, the executing the instantiated test case includes:
inserting bottoming data in the instantiated test case into a database;
executing a corresponding test method on the test object;
and executing the assertion in the instantiated test case, and judging whether the execution result of the test object is consistent with the expected result.
Optionally, after executing the instantiated test case, the method further includes:
and executing the integral rollback operation of the database so as to restore the database to the state before the instantiated test case is executed.
A unit testing apparatus comprising:
the test case obtaining unit is used for obtaining a test case which is constructed in advance according to a preset variable rule, and the test case comprises: backing data, test objects and assertions;
the test case analysis unit is used for analyzing the test case to obtain the value format of each target field which accords with the preset variable rule, and the target field comprises a main key field;
a test case instantiation unit used for respectively obtaining the value format of each target field, randomly generating a character string as a value of the corresponding target field to realize instantiation of the test case;
and the test case execution unit is used for executing the instantiated test case.
Optionally, the apparatus further comprises:
the test case building unit is used for determining the bottoming data, the test object and each target field and non-target field including the main key field in the assertion in the test case; respectively generating a value format of each target field according to the preset variable rule and the variable name, the variable type and the variable length of each target field; and generating the value of the non-target field according to the unit test requirement.
Optionally, the test case parsing unit is specifically configured to:
scanning the test case, and extracting each target field with a value format meeting the preset variable rule;
and respectively analyzing the value format of each target field to obtain the variable name, the variable type and the variable length of each target field.
Optionally, the test case execution unit is specifically configured to:
inserting bottoming data in the instantiated test case into a database;
executing a corresponding test method on the test object;
and executing the assertion in the instantiated test case, and judging whether the execution result of the test object is consistent with the expected result.
Optionally, the apparatus further comprises:
and the rollback execution unit is used for executing the integral rollback operation of the database after the instantiated test case is executed so as to restore the database to the state before the instantiated test case is executed.
Compared with the prior art, the invention has the following beneficial effects:
the invention discloses a unit testing method and a unit testing device, which construct a testing case comprising bottoming data, a testing object and assertion in advance according to a preset variable rule, obtain a value format of a main key field conforming to the preset variable rule by analyzing the testing case before executing the testing case, randomly generate a character string according to the value format of the main key field, and obtain a unique instantiated testing case of a main key value as the value of the main key field. The primary key values meeting the preset variable rule are randomly generated every time the unit test is executed, the bottoming data, the test objects and the asserted primary key values of all the reference primary keys in the same test case in the same unit test are consistent, the primary key values of the same test case in different unit tests are different, the problem of unit test failure caused by primary key collision is avoided in concurrent execution, and the unit test efficiency is effectively improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the prior art descriptions will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a schematic flow chart illustrating a unit testing method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an example of a test according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram illustrating an instantiation of a test case disclosed in an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a unit testing apparatus according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, 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 invention.
In order to facilitate understanding of the technical solutions disclosed in the embodiments of the present invention, terms that may be involved are explained below.
Unit testing: unit testing is a work of verifying and testing the correctness of a program module by a developer or a tester to check whether the function of a code under test is correct. The unit test is actually to perform detection on functions realized by modules, classes and functions, and is a one-time checking and checking process to see whether the expected functions are met or not and whether the function requirements are met or not.
And (3) primary key conflict: in a database, each piece of data typically has a field or fields that uniquely identify a record in the table. For example, if the basic information of a person is stored in the database, the identification number can be used as a primary key, because the identification number can uniquely correspond to the person. The primary key conflict means that when a record is inserted, if the primary key value of the inserted record already exists in the existing database, the primary key conflict is generated because the primary key cannot be repeated.
Test case: a test case, also called test case, is a set of test inputs, execution conditions, and expected results that are tailored to a particular target in order to test whether a program meets a particular requirement.
Bottom laying data: the backing data is data stored in the database according to business logic before testing. These data can be considered as garbage data because they have no real impact on the business logic of the system, but have much impact on the testing of the system, which can be the underlying data used for testing.
Assertion (assert): assertions are a common means in programming. In general, an assertion is a statement that always requires a return value to be placed in a true predicate for the exclusion of cases that should not be generated on the logic of the design. In short, an assertion is a piece of code written by a developer that tests whether the result of execution completion is consistent with the expected result.
The inventor finds out through research that: for the situation that a plurality of different test processes run a full number of test cases simultaneously, at present, two solutions are generally available. One solution is to avoid different test processes from running the same test case at the same time as much as possible. For example, the whole number of unit test cases are numbered in the specified sequence, and a unit test operation state table is maintained in the database. Before a certain unit test case is operated, whether a test process of the unit test case is operated or not is inquired in the table, if not, the test case is indicated to be executed without the process, the current test process can execute the test case, the unit test case is marked to be executed in the unit test operation state table, then the case is executed, and after the execution is finished, records are deleted from the unit test operation state table. If the test case is inquired that a process is running before the test case of the execution unit, the process waits for a period of time randomly, the inquiry step is executed repeatedly until no process of the test case is executed, and the test process executes the test case. In addition, a random character string replacement mode is adopted, namely a random character string is used when the main key of the test case is set, so that the main key is random when the test case is generated every time, and the main key conflict can be avoided.
For the first solution, the database needs to be additionally connected during unit testing, and a special test table for maintaining the running state of the test case is created, which is useless for the application logic of unit testing, so that certain resource waste is caused, and when certain IO (input/output) is used for inquiring, newly adding or deleting database data each time, the running efficiency of unit testing is reduced, and in addition, random waiting is performed when the running conflict exists, so that the testing time is further prolonged.
For the second solution, although the problem of primary key conflict is solved to a certain extent, the processing method is too simple and rough, and the problem of parameter dependence cannot be solved. For example, when we want to test a transaction for processing an application form, we need to insert underlying data into a unit test case, for example, insert an application form with a state "to be checked", and then execute a unit test, and the business logic of the unit test finds out the application form and changes the state of the application form to "pass". This requires that the main key of the inserted background data is consistent with the main key of the test case, otherwise, the application form cannot be found in the unit test execution process, and the execution result is not correct.
In order to solve the problems in the prior art, the invention provides a unit testing method and a unit testing device, a test case comprising bottoming data, a test object and assertion is constructed in advance according to a preset variable rule, before the test case is executed, the value format of a primary key field conforming to the preset variable rule is obtained by analyzing the test case, a character string is randomly generated according to the value format of the primary key field and is used as the value of the primary key field, and the test case after instantiation with a unique primary key value is obtained. The primary key values meeting the preset variable rule can be randomly generated every time the unit test is executed, the bottoming data, the test objects and the asserted primary key values of all the primary keys quoted in the same test case in the same unit test are consistent, the primary key values of the same test case in different unit tests are different, the problem of unit test failure caused by primary key collision in concurrent execution is solved, and the unit test efficiency is effectively improved.
Specifically, referring to fig. 1, the unit testing method disclosed in this embodiment includes the following steps:
s101: obtaining a test case constructed in advance according to a preset variable rule, wherein the test case comprises: backing data, test objects and assertions;
the test case not only comprises the test object, but also comprises data required by relevant tests such as bottoming data, assertion and the like.
The construction method of the test case comprises the following steps: the method comprises the steps of firstly determining all target fields and non-target fields including main key fields in backing data, test objects and assertions in a test case, then respectively generating a value format of each target field according to a preset variable rule and variable names, variable types and variable lengths of all target fields, and finally generating values of the non-target fields according to unit test requirements.
Taking a transaction of processing an application form by testing a transaction as an example, the backing data is application form data with a state of 'to be audited', the test object is in an application state, the backing data, the test object and the target field in the assertion comprise an application form number and application time, the non-target field is in an application state, the application form number is a main key field, if the unit test requirement is that the application form state is changed to 'audit pass', the application state of the application form in the backing data is to be audited, and the application state of the application form in the assertion is audit pass.
An alternative variable rule is as follows:
$ random (variable length) _ variable type _ variable name }
The { } represents the value format of the field, and starts with random (variable length) to represent the construction of a random variable with a specified length.
It should be noted that some fields need not define a variable length, such as a date or time, in which case the variable length may be empty. Some fields support control of random string length, ensuring that insertion into the database is not too long.
The variable name represents the name defined by the developer for the whole variable, and the same value of random character strings with the same name is ensured to be consistent in the same test case. The variable name is also an option, and the developer may not specify the variable name if it is not necessary to ensure that the values are consistent, in which case the variable name may also be null.
The variable type may be a string, a number, or a string + number. For example, random (3) _ str denotes a character string of length 3, and random (3) _ int denotes a number of length 3
And the values of the variables corresponding to the same variable name in the same test case are the same. For example, we define a field variable $ { random (3) _ str _ id } in a test case, which means that the name of this variable at run-time is id, which is a string of length 3. Then the same value is used in the test case whether the variable is used in the bottoming data, the test object, or the assertion. Taking the above-mentioned modified application form state as an example, please refer to the test case diagram in fig. 2, it is necessary to ensure that the number of the bottomed application form is consistent with the number of the application form of the test object, otherwise, the bottomed application form cannot be found according to the number of the application form of the test object.
S102: analyzing the test case to obtain the value format of each target field which accords with a preset variable rule, wherein the target field comprises a main key field;
specifically, after a test case is obtained, bottoming data, a test object and assertion in the test case are scanned, each target field with a value format according with a preset variable rule is extracted, and then the value format of each target field is analyzed according to the preset variable rule to obtain a variable name, a variable type and a variable length of each target field.
Taking the test case in fig. 2 as an example, please refer to fig. 3, the target field obtained through parameter extraction includes: $ random (3) _ str _ appno }, $ random _ date }. After parameter analysis, the variable name of $ random (3) _ str _ appno } is appno, the variable type is str, the variable length is 3, $ { random _ date } the variable type is date, and the variable name and the variable length are null.
Further, in order to ensure that the extracted target field is a field meeting the preset variable rule, it may be checked again whether the value format of the target field meets the preset variable rule in the process of analyzing the value format of each target field.
S103: respectively randomly generating character strings according to the value format of each target field, and using the character strings as the values of the corresponding target fields to realize instantiation of the test cases;
referring to fig. 3, after obtaining the value formats of the target fields that meet the preset variable rule, instantiating the test case, randomly generating a random string with a length of 3, such as abc, according to $ { random (3) _ str _ appno }, and randomly generating a date, such as 2022-01-01, according to $ { random _ date }; in another unit test, a random string of length 3, such as xyz, is randomly generated according to $ { random (3) _ str _ appno }, and a date, such as 2022-06-01, is randomly generated according to $ { random _ date }.
The variable name of each field and the corresponding generated random character string are stored in a key-value pair mode, and the storage mode is not limited to a database, a memory, a cache or a file.
It should be noted that, in the instantiated test case, the values of the primary key fields in the backing data, the test object, and the assertion are consistent, and the values of the other target fields are also consistent.
S104: and executing the instantiated test case.
Specifically, the bottoming data in the instantiated test case is inserted into the database, then a corresponding test method is executed on the test object, finally assertion in the instantiated test case is executed, whether the execution result corresponding to the test is consistent with the expected result or not is judged, if the expected result of the unit test is that the state of the application form is changed from 'to be audited' to 'audit pass', after the test method is executed on the test object, whether the application state of the application form is audit pass or not is judged.
Further, in order to ensure that the bottoming data inserted in the unit test and the data modified by the unit test do not interfere with the data with the real business meaning in the database, after the unit test is finished, the whole rollback operation of the database is executed, so that the database is restored to the state before the instantiated test case is executed.
Referring to fig. 3, a test process 1 and a test process 2 respectively execute a unit test, and both perform the same test case, after analyzing the value format of the same target field (i.e., application _ no and application _ time, where application _ no is a primary key field) for the test case, randomly generating a character string according to the value format of the target field, as a value of the corresponding target field, to instantiate the test case, as can be seen from fig. 3, the values of the target fields of the test cases after instantiation of the test process 1 and the test process 2 are different, the value of application _ no in the test process 1 is abc, the value of application _ no in the test process 2 is xyz, the value of application _ time in the test process 1 is 2022-01-01, and the value of application _ time in the test process 2 is 2022-06-01, thereby effectively avoiding the problem of unit test failure due to primary key collision.
It can be seen that, in the unit testing method disclosed in this embodiment, a test case including bottoming data, a test object, and assertion is constructed in advance according to a preset variable rule, before the test case is executed, a value format of a primary key field that meets the preset variable rule is obtained by analyzing the test case, and a character string is randomly generated according to the value format of the primary key field and is used as a value of the primary key field, so that an instantiated test case with a unique primary key value is obtained. The primary key values meeting the preset variable rule can be randomly generated every time the unit test is executed, the bottoming data, the test objects and the asserted primary key values of all the primary keys quoted in the same test case in the same unit test are consistent, the primary key values of the same test case in different unit tests are different, the problem of unit test failure caused by primary key collision in concurrent execution is solved, and the unit test efficiency is effectively improved.
Based on the unit testing method disclosed in the above embodiment, this embodiment correspondingly discloses a unit testing apparatus, please refer to fig. 4, which includes:
a test case obtaining unit 401, configured to obtain a test case that is constructed in advance according to a preset variable rule, where the test case includes: backing data, test objects and assertions;
a test case analyzing unit 402, configured to analyze the test case to obtain a value format of each target field that meets the preset variable rule, where the target field includes a primary key field;
a test case instantiation unit 403, configured to randomly generate a character string as a value of the corresponding target field according to the value format of each target field, so as to instantiate the test case;
a test case execution unit 404, configured to execute the instantiated test case.
Optionally, the apparatus further comprises:
the test case building unit is used for determining the bottoming data, the test object and each target field and non-target field including the main key field in the assertion in the test case; respectively generating a value format of each target field according to the preset variable rule and the variable name, the variable type and the variable length of each target field; and generating the value of the non-target field according to the unit test requirement.
Optionally, the test case analyzing unit 402 is specifically configured to:
scanning the test case, and extracting each target field with a value format meeting the preset variable rule;
and analyzing the value format of each target field respectively to obtain the variable name, the variable type and the variable length of each target field.
Optionally, the test case executing unit 404 is specifically configured to:
inserting bottoming data in the instantiated test case into a database;
executing a corresponding test method on the test object;
and executing the assertion in the instantiated test case, and judging whether the execution result of the test object is consistent with the expected result.
Optionally, the apparatus further comprises:
and the rollback execution unit is used for executing the integral rollback operation of the database after the instantiated test case is executed so as to restore the database to the state before the instantiated test case is executed.
The unit testing device disclosed in this embodiment is configured to build a test case including bottoming data, a test object, and assertion in advance according to a preset variable rule, obtain a value format of a primary key field that meets the preset variable rule by analyzing the test case before executing the test case, and randomly generate a character string according to the value format of the primary key field, where the character string is used as a value of the primary key field, to obtain a unique instantiated test case of a primary key value. The primary key values meeting the preset variable rule can be randomly generated every time the unit test is executed, the bottoming data, the test objects and the asserted primary key values of all the primary keys quoted in the same test case in the same unit test are consistent, the primary key values of the same test case in different unit tests are different, the problem of unit test failure caused by primary key collision in concurrent execution is solved, and the unit test efficiency is effectively improved.
In the present specification, the embodiments 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 in the embodiment corresponds to the method disclosed in the embodiment, so that the description is simple, and the relevant points can be referred to the description of the method part.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or apparatus that comprises the element.
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 above embodiments can be combined arbitrarily, and the features described in the embodiments in the present specification can be replaced or combined with each other in the above description of the disclosed embodiments, so that those skilled in the art can implement or use the present application.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. 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 invention. Thus, the present invention 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 of unit testing, comprising:
obtaining a test case which is constructed in advance according to a preset variable rule, wherein the test case comprises: backing data, test objects and assertions;
analyzing the test case to obtain the value format of each target field which accords with the preset variable rule, wherein the target field comprises a main key field;
respectively randomly generating character strings according to the value format of each target field, and using the character strings as the values of the corresponding target fields to realize instantiation of the test case;
and executing the instantiated test case.
2. The method according to claim 1, wherein the method for constructing the test case comprises:
determining each target field and non-target field including a primary key field in bottoming data, a test object and assertion in the test case;
respectively generating a value format of each target field according to the preset variable rule and the variable name, the variable type and the variable length of each target field;
and generating the value of the non-target field according to the unit test requirement.
3. The method of claim 1, wherein analyzing the test case to obtain a value format of each target field that meets the preset variable rule comprises:
scanning the test case, and extracting each target field with a value format meeting the preset variable rule;
and analyzing the value format of each target field respectively to obtain the variable name, the variable type and the variable length of each target field.
4. The method of claim 1, wherein the executing the instantiated test case comprises:
inserting bottoming data in the instantiated test case into a database;
executing a corresponding test method on the test object;
and executing the assertion in the instantiated test case, and judging whether the execution result of the test object is consistent with the expected result.
5. The method of claim 1, wherein after executing the instantiated test cases, the method further comprises:
and executing the integral rollback operation of the database so as to restore the database to the state before the instantiated test case is executed.
6. A unit testing apparatus, comprising:
the test case acquisition unit is used for acquiring a test case which is constructed in advance according to a preset variable rule, and the test case comprises: backing data, test objects and assertions;
the test case analysis unit is used for analyzing the test case to obtain the value format of each target field which accords with the preset variable rule, and the target field comprises a main key field;
the test case instantiation unit is used for randomly generating character strings as values of the corresponding target fields according to the value formats of the target fields respectively so as to realize instantiation of the test cases;
and the test case execution unit is used for executing the instantiated test case.
7. The apparatus of claim 6, further comprising:
the test case building unit is used for determining the bottoming data, the test object and each target field and non-target field including the main key field in the assertion in the test case; respectively generating a value format of each target field according to the preset variable rule and the variable name, the variable type and the variable length of each target field; and generating the value of the non-target field according to the unit test requirement.
8. The apparatus according to claim 6, wherein the test case parsing unit is specifically configured to:
scanning the test case, and extracting each target field with a value format conforming to the preset variable rule;
and respectively analyzing the value format of each target field to obtain the variable name, the variable type and the variable length of each target field.
9. The apparatus of claim 6, wherein the test case execution unit is specifically configured to:
inserting bottoming data in the instantiated test case into a database;
executing a corresponding test method on the test object;
and executing the assertion in the instantiated test case, and judging whether the execution result of the test object is consistent with the expected result.
10. The apparatus of claim 6, further comprising:
and the rollback execution unit is used for executing the integral rollback operation of the database after the instantiated test case is executed so as to restore the database to the state before the instantiated test case is executed.
CN202211278548.3A 2022-10-19 2022-10-19 Unit testing method and device Pending CN115470147A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211278548.3A CN115470147A (en) 2022-10-19 2022-10-19 Unit testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211278548.3A CN115470147A (en) 2022-10-19 2022-10-19 Unit testing method and device

Publications (1)

Publication Number Publication Date
CN115470147A true CN115470147A (en) 2022-12-13

Family

ID=84337296

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211278548.3A Pending CN115470147A (en) 2022-10-19 2022-10-19 Unit testing method and device

Country Status (1)

Country Link
CN (1) CN115470147A (en)

Similar Documents

Publication Publication Date Title
Langer et al. A posteriori operation detection in evolving software models
Kamimura et al. Extracting candidates of microservices from monolithic application code
CN108763091B (en) Method, device and system for regression testing
CN111382070B (en) Compatibility testing method and device, storage medium and computer equipment
US20070061641A1 (en) Apparatus and method for generating test driver
Chen et al. Extracting and studying the Logging-Code-Issue-Introducing changes in Java-based large-scale open source software systems
EP3693860B1 (en) Generation of test models from behavior driven development scenarios based on behavior driven development step definitions and similarity analysis using neuro linguistic programming and machine learning mechanisms
Granda et al. What do we know about the defect types detected in conceptual models?
CN114756456A (en) Continuous integration method and device and computer readable storage medium
CN114780109B (en) Python project third-party library dependent automatic analysis and installation method
US11422917B2 (en) Deriving software application dependency trees for white-box testing
Rantala et al. Prevalence, contents and automatic detection of KL-SATD
Zhang et al. Model based testing for agent systems
Schlie et al. Clustering variation points in matlab/simulink models using reverse signal propagation analysis
CN117493188A (en) Interface testing method and device, electronic equipment and storage medium
CN109542496B (en) Method, device and system for determining incremental code
WO2023223148A1 (en) Techniques for identifying and validating security control steps in software development pipelines
CN115795059A (en) Threat modeling method and system for agile development
CN115470147A (en) Unit testing method and device
US11740895B2 (en) Generation of software program repair explanations
CN115422059A (en) Automatic test case generation system, method, equipment and storage medium
Seresht et al. Automated assistance for use cases elicitation from user requirements text
CN114356783A (en) Method and device for automatically generating unit test code, storage medium and equipment
Habibi et al. Generating test as a web service (TaaWS) through a method-based attribute grammar
CN114153447A (en) Method for automatically generating AI training code

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