CN108595342A - Unit test method and device - Google Patents

Unit test method and device Download PDF

Info

Publication number
CN108595342A
CN108595342A CN201810455233.9A CN201810455233A CN108595342A CN 108595342 A CN108595342 A CN 108595342A CN 201810455233 A CN201810455233 A CN 201810455233A CN 108595342 A CN108595342 A CN 108595342A
Authority
CN
China
Prior art keywords
information
test
unit
code
version information
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.)
Granted
Application number
CN201810455233.9A
Other languages
Chinese (zh)
Other versions
CN108595342B (en
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.)
Hangzhou Zan Technology Co Ltd
Original Assignee
Hangzhou Zan Technology 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 Hangzhou Zan Technology Co Ltd filed Critical Hangzhou Zan Technology Co Ltd
Priority to CN201810455233.9A priority Critical patent/CN108595342B/en
Publication of CN108595342A publication Critical patent/CN108595342A/en
Application granted granted Critical
Publication of CN108595342B publication Critical patent/CN108595342B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

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 discloses a kind of unit test method and devices, wherein method includes:The lower test object inputted of active cell test is obtained, each category information corresponding with test object and method information are obtained by reflex mechanism, successively according to each category information and method information according to preset rules and pre-set code template generation unit testing code;Unit testing code includes combination straw line key information;Associated configured list is loaded from database according to combination straw line key information, and configured list is parsed, is successively read all test case datas for parsing and obtaining, and execution unit tests code, and test report is generated according to implementing result.It not only realizes automatically generating unit test code, greatly improves the development efficiency of unit testing code;And load associated configured list from database by combining straw line key information and can realize the automation of unit testing, test errors caused by human factor are avoided, testing efficiency and accuracy rate are improved.

Description

Unit test method and device
Technical field
The present invention relates to software testing technology field more particularly to a kind of unit test methods and device.
Background technology
Unit testing is a kind of white-box testing, it is intended to which the mistake in inspection software code and loophole ensure soft from source The quality of part is to carry out coverage test to the every line code of software or code block to judge its correctness.In software development It played an important role in journey, be very effective code quality and ensure means.In the prior art, unit test method master If carrying out manual coding by developer in conjunction with some test frames (such as Junit, Testng) increased income, then by artificial It writes a large amount of test case code and removes the covering each branching logic of code, to carry out test verification to source program code, and lead to It crosses compiling and generates test report, then by understanding test data puzzling in test report, finally can just judge source journey Mistake in sequence code and loophole.
Above-mentioned technological deficiency of the existing technology is:During writing test case, need to put into more essence Power or even input ratio service code develop more time energy to write the unit testing code for covering each scene, time Cost is higher;And there are excessive manual interventions, and there are test errors caused by human factor, therefore source program is made to leave or more Or few loophole fails to find in time, reduces testing efficiency.
Invention content
The object of the present invention is to provide a kind of unit test method and devices, not only realize automatically generating unit test generation Code, greatly improves the development efficiency of unit testing code;And association is loaded from database by combining straw line key information Configured list can realize the automation of unit testing, avoid test errors caused by human factor, improve testing efficiency and Accuracy rate.
The present invention provides a kind of unit test methods, include the following steps;
The lower test object inputted of active cell test is obtained, is obtained by reflex mechanism corresponding with the test object Each category information and method information, successively according to each category information and method information according to preset rules and pre-set code mould Plate generation unit tests code;The unit testing code includes combination straw line key information;
Load associated configured list from database according to the combination straw line key information, and to the configured list into Row parsing, obtains test case data;
All test case datas are successively read, and execute the unit testing code, are given birth to according to implementing result At test report.
It is described that associated configuration is loaded from database according to the combination straw line key information as a kind of embodiment List includes the following steps;
It is loaded from local data base according to the combination straw line key information and associated list and local version is locally configured Information;
The current version information for obtaining test case, the local version information and the current version information are compared To judging;
If the local version information is consistent with the version of current version information, list will be locally configured and be changed to Configured list;
If the version of the local version information and the current version information is inconsistent, according to the combination straw line key Information loads associated high in the clouds configured list and high in the clouds version information from the database of Cloud Server, and the high in the clouds is configured List and high in the clouds version information are stored, and replace list and local version letter are locally configured described in local data base respectively Breath.
As a kind of embodiment, it is described successively according to each category information and method information according to preset rules and Pre-set code template generation unit testing code, includes the following steps;
Suffix restriction processing is carried out to each category information according to the preset rules, meanwhile, according to the preset rules pair Each method information carries out prefix restriction processing;
Each category information that will limit that treated successively and method information corresponding with category information are according to pre-set code template Execution processing is carried out, generation unit tests code;The pre-set code template includes into ginseng conversion rigging, executes test side Method template and outcome expectancy contrast mould.
It is described to be successively read all test case datas as a kind of embodiment, and execute the unit Code is tested, test report is generated according to the expected results in implementing result and test case data, includes the following steps;
Be successively read all test case datas, each test case data include use-case enter parameter according to, External call analogue data and execution expected results;
Enter parameter evidence and external call analogue data according to each use-case to execute the unit testing code Processing, is compared according to implementing result and execution expected results, and test report is generated according to comparison result.
As a kind of embodiment, unit test method provided by the invention is further comprising the steps of;
In the case where obtaining active cell test before the test object that inputs, obtain with the category information of all kinds of objects to be tested and Corresponding method information, and obtain use-case corresponding with the method information and enter parameter evidence and external call analogue data;
It will be in all kinds of category informations and corresponding method data input Cloud Server;In typing, addition and the side The corresponding use-case of method information enters parameter evidence, external call analogue data and executes expected results, and generation includes that test is used The configured list of number of cases evidence, configured list and combine the associated key-value pair information of straw line key information and current version information.
Correspondingly, the present invention also provides a kind of unit testing device, including generation module, load parsing module and execution Module;
The generation module, for obtaining the lower test object inputted of active cell test, by reflex mechanism obtain with The corresponding each category information of the test object and method information, successively according to each category information and method information according to pre- If rule and pre-set code template generation unit testing code;The unit testing code includes combination straw line key information;
The load parsing module is arranged for loading associated configuration from database according to the combination straw line key information Table, and the configured list is parsed, obtain test case data;
The execution module for being successively read all test case datas, and executes the unit testing generation Code generates test report according to implementing result.
As a kind of embodiment, the load parsing module include loading unit, judging unit, changing unit and Replacement unit;
The loading unit is matched for loading associated local from local data base according to the combination straw line key information Set list and local version information;
The judging unit, the current version information for obtaining test case, by the local version information with it is described Judgement is compared in current version information;
The changing unit will if consistent with the version of current version information for the local version information List is locally configured and is changed to configured list;
The replacement unit, if the version for the local version information and the current version information is inconsistent, Associated high in the clouds configured list and high in the clouds version letter are loaded from the database of Cloud Server according to the combination straw line key information Breath, and the high in the clouds configured list and high in the clouds version information are stored, it replaces locally match described in local data base respectively Set list and local version information.
As a kind of embodiment, the generation module includes limiting unit and generation unit;
The restriction unit, for carrying out suffix restriction processing to each category information according to the preset rules, meanwhile, according to Prefix restriction processing is carried out to each method information according to the preset rules;
The generation unit, for will limit that treated successively each category information and method information corresponding with category information Execution processing is carried out according to pre-set code template, generation unit tests code;The pre-set code template includes into joining conversion group Decking executes test method template and outcome expectancy contrast mould.
As a kind of embodiment, the execution module includes reading unit and execution unit;
The reading unit, for being successively read all test case datas, each test case data Enter parameter evidence, external call analogue data including use-case and executes expected results;
The execution unit, for entering parameter evidence and external call analogue data to the unit according to each use-case Test code carries out execution processing, is compared according to implementing result and execution expected results, is generated and tested according to comparison result Report.
As a kind of embodiment, unit testing device provided by the invention further includes typing management module;
The typing management module, for before the test object inputted under obtaining active cell test, obtaining and each The category information of class object to be tested and corresponding method information, and obtain corresponding with the method information use-case enter parameter evidence and External call analogue data;
It will be in all kinds of category informations and corresponding method data input Cloud Server;In typing, addition and the side The corresponding use-case of method information enters parameter evidence, external call analogue data and executes expected results, and generation includes that test is used The configured list of number of cases evidence, configured list and combine the associated key-value pair information of straw line key information and current version information.
Compared with prior art, the technical program has the following advantages:
Unit test method and device provided by the invention, it is only necessary to the test pair that user inputs in active cell test As each category information corresponding with test object and method information, and then basis successively can be obtained automatically by reflex mechanism Each category information and method information are according to preset rules and pre-set code template generation unit testing code;Further according to unit testing Combination straw line key information in code loads associated configured list from database, and is parsed to configured list;Finally All test case datas for parsing and obtaining are successively read, and execution unit tests code, test report is generated according to implementing result It accuses;To not only realize automatically generating unit test code, the development efficiency of unit testing code is greatly improved;And pass through Combination straw line key information loads associated configured list from database and can realize the automation of unit testing, avoid it is artificial because Test errors caused by element improve testing efficiency and accuracy rate.
Description of the drawings
Fig. 1 is the flow diagram for the unit test method that the embodiment of the present invention one provides;
Fig. 2 is the structural schematic diagram for the unit testing device that the embodiment of the present invention three provides;
Fig. 3 is the structural schematic diagram that parsing module is loaded in Fig. 2.
In figure:100, generation module;110, unit is limited;120, generation unit;200, parsing module is loaded;210, it loads Unit;220, judging unit;230, changing unit;240, replacement unit;300, execution module;310, reading unit;320, it holds Row unit;400, typing management module.
Specific implementation mode
Below in conjunction with attached drawing, the technical characteristic and advantage above-mentioned and other to the present invention are clearly and completely described, Obviously, described embodiment is only the section Example of the present invention, rather than whole embodiments.
Referring to Fig. 1, the unit test method that the embodiment of the present invention one provides, includes the following steps;
S100, the lower test object inputted of active cell test is obtained, is obtained by reflex mechanism corresponding with test object Each category information and method information, successively according to each category information and method information according to preset rules and pre-set code template Generation unit tests code;Unit testing code includes combination straw line key information;
S200, associated configured list is loaded from database according to combination straw line key information, and configured list is carried out Parsing, obtains test case data;
S300, all test case datas are successively read, and execution unit tests code, are generated and is surveyed according to implementing result Examination report.
It should be noted that test object includes being not limited to class name, packet name or class name and packet name;Unit is being carried out every time When test, according to the difference of active cell test, the test object of input can have difference.That is to an engineering into Row unit testing is determined according to the content of engineering active cell test.If a class, in packet, test object can be class Name and its such where packet name.Subject to the data for including in Practical Project of the test object according to active cell test. When test object is packet name, the corresponding each category information of each packet name and method information are obtained by reflex mechanism, category information with Method information corresponds to, and a category information can correspond to multiple method information, and the type of category information includes class and interface.
In this present embodiment, configured list and combination straw line key information are with the association of key-value pair (key-valueList) Form is stored in database, and combination straw line key information can be with " engineering name+class name+method name " as a key assignments key Combining form realize.Straw line key information is combined in an engineering has uniqueness.And configured list (valueList) is Chained list or array, representative is that this key correspondences have one or more test case datas, and each test case data can To include that use-case enters parameter evidence, external call analogue data and execution expected results.When execution unit tests code These data can be preferentially loaded into inside memory, and the key-valueList structures that can also maintain like so are held every time As long as being taken out pair by the combination straw line key information of " engineering name+class name+method name " when row unit testing code These test case datas answered.
And when execution unit test code is tested, all test case datas are successively read, according still further to reading Sequencing executed.For example, there are two method, login and query for tool in a class.It is first to read at the time of reading The corresponding test case datas of login, then read the corresponding test case datas of query;So it is being successively read all surveys After trying use-case data, unit testing code corresponding with login is first carried out, then execute unit testing code corresponding with query. In other embodiment, it can also be that method information recycles for one, read the corresponding test case number of a method information According to, execute once for unit testing code.Of course for operational efficiency is improved, can also be carried out at the same time.
Unit test method and device provided by the invention, it is only necessary to the test pair that user inputs in active cell test As each category information corresponding with test object and method information, and then basis successively can be obtained automatically by reflex mechanism Each category information and method information are according to preset rules and pre-set code template generation unit testing code;Further according to unit testing Combination straw line key information in code loads associated configured list from database, and is parsed to configured list;Finally All test case datas for parsing and obtaining are successively read, and execution unit tests code, test report is generated according to implementing result It accuses;To not only realize automatically generating unit test code, the development efficiency of unit testing code is greatly improved;And pass through Combination straw line key information loads associated configured list from database and can realize the automation of unit testing, avoid it is artificial because Test errors caused by element improve testing efficiency and accuracy rate.
In order to improve test accuracy rate, when loading associated configured list it needs to be determined that configured list is newest configuration List.In general, when updating configured list and test case data therein every time, it can all be uploaded to cloud after the update is completed It is preserved in server.And when locally carrying out unit testing, it needs first to judge whether local configured list is newest, if It needs to download newest configured list into Cloud Server without being, in this way it is avoided that test caused by expired test case data Mistake.Certainly in other embodiment, can also directly by newest configured list and test case data therein directly more Newly to local.
In this present embodiment, it is utilized in after update and configured list and test case data therein is uploaded to cloud service The mode preserved in device is below described in detail the step of this mode.According to combination straw line key information from database Associated configured list is loaded, is included the following steps;
S210, it is loaded from local data base according to combination straw line key information and associated list and local version is locally configured Information;
S220, the current version information for obtaining test case, local version information is compared with current version information Judge;
If S230, local version information are consistent with the version of current version information, list will be locally configured and be changed to match Set list;
If S240, local version information and the version of current version information are inconsistent, according to combination straw line key information from Load associated high in the clouds configured list and high in the clouds version information in the database of Cloud Server, and by high in the clouds configured list and high in the clouds Version information is stored, and replaces in local data base list and local version information is locally configured respectively.
Upon each update, newer data can be all uploaded to Cloud Server, and will current newer version information As high in the clouds version information.That is the data of Cloud Server of being subject to storage, as long as local version information and current version The version of information is inconsistent, just downloads high in the clouds configured list and high in the clouds version information from Cloud Server.I.e. local data are clouds One backup copies of server.To ensure that configured list is newest, the test errors caused by version updating are avoided.
Further, successively according to each category information and method information according to preset rules and pre-set code template generation list Member test code, includes the following steps;
S110, suffix restriction processing is carried out to each category information according to preset rules, meanwhile, according to preset rules to each Method information carries out prefix restriction processing;
S120, each category information that will limit that treated successively and method information corresponding with category information are according to pre-set code Template carries out execution processing, and generation unit tests code;Pre-set code template includes into ginseng conversion rigging, executes test side Method template and outcome expectancy contrast mould.
Category information is different with the restrictive rule of method information, and in this present embodiment, the preset rules of category information are each Increase suffix behind category information to limit, and the preset rules of method information are to increase prefix before each method information to limit. Enter to join conversion rigging, execution test method template and outcome expectancy contrast mould after restriction, then according to preset Realize the generation of unit testing code.
It illustrates below and said units test code generation process is described in detail.
Such as:Inside this class of UserService include two sides in this engineering assuming that an engineering account Method (login and query), and the entitled com.xx.service of packet where UserService this class.
Then test object is UserService.By the reflex mechanism of Java obtain category information (UserService) and Method information (login and query), then successively according to each category information and method information according to preset rules and pre-set code Template generation unit testing code.Specific preset rules are as follows:Preset rules 1, test class class name are with former class name+" Test " suffix To name;Mainly category information is limited.Test method in preset rules 2, test class is with " test " prefix+original method name It names, and incoming request (Map forms) enters ginseng and expected Result expected results;Mainly to method information It is limited, while the use-case of incoming request forms enters parameter according to this and executes expected results.It is to need to execute expected results It to be tested according to test case data.
Foundation enters ginseng conversion rigging, executes test method mould successively for the realization of preset rules 3, unit testing code Plate, outcome expectancy contrast mould this 3 steps Code Template realize.Enter ginseng conversion rigging:It can be reflected by Java Mechanism obtains category information and method information (including be not limited to parameter type, parameter name information and return to Value Types), according to ginseng Several classes of types and parameter name information are from Map<String, Object>Request be converted to automatically unit testing code needs enter ginseng The use-case of list, such as the method information of above-mentioned unit testing code login enters parameter according to the parameter for being two String types, just It can be automatically from Map<String, Object>The two String use-cases are obtained in request enters parameter evidence.Execute test method Template:Enter to join DEU data execution unit test code according to currently incoming use-case and obtains implementing result, the return of implementing result Value Types are also to be acquired according to Java reflex mechanisms.Outcome expectancy contrast mould:Unit testing code is executed to obtain Result and expected results compared, acquiescence can be turned to using object sequence to be carried out total head matching after character string and compares, Support self-defined comparison.
It is the flow of single class automatically generating unit test code that above-mentioned, which is for test object, if wanting test object Be a packet has multiple classes below.It can then recycle and sequentially generate this unit testing code for wrapping following all classes.
According to above-mentioned rule, for object class UserService to be tested, the unit testing code of generation is as follows;
Further, all test case datas are successively read, and execution unit tests code, according to implementing result and Expected results in test case data generate test report, include the following steps;
All test case datas are successively read, each test case data includes that use-case enters parameter evidence, external call Analogue data and execution expected results;
Enter parameter evidence according to each use-case and external call analogue data carries out execution processing to unit testing code, according to Implementing result and execution expected results are compared, and test report is generated according to comparison result.
Test report includes comparison result, error message and version information etc..It can directly be surveyed from test report Test result improves testing efficiency.When the result and expected results for executing unit testing code are compared, acquiescence Progress total head matching compares after character string can be turned to using object sequence, also supports self-defined comparison.If it is self-defined ratio To then needing to preset customized value.
Further, unit test method provided by Embodiment 2 of the present invention further includes following step compared with embodiment one Suddenly;
In the case where obtaining active cell test before the test object that inputs, obtain with the category information of all kinds of objects to be tested and Corresponding method information, and obtain use-case corresponding with method information and enter parameter evidence and external call analogue data;By all kinds of classes In information and corresponding method data input Cloud Server;In typing, add corresponding with method information use-case enter parameter evidence, External call analogue data and execution expected results, generation include the configured list, configured list and group of test case data Close the associated key-value pair information of straw line key information and current version information.
Typing in Cloud Server can also be to be carried out in case management platform in Cloud Server.If it is with Typing is carried out in example management platform, is registered when recording first time, registration can previous management platform after completing Test case data is added in the inside, and process can be that typing needs category information to be tested and corresponding method information;Category information For class or interface.The use-case of adding device test code enters parameter evidence;Associative cell tests the external call simulation that code needs Data;Judge whether have external call analogue data;If no, repeating above-mentioned steps, i.e. typing waits for simulation test Category information and corresponding method information, and add external call analogue data, finally execute expected results.If so, then straight Addition external call analogue data is connect, execution expected results are then added.Test data after recording again may be by " engineering name+class name+method name " retrieves for key, and can check that test code has covered at present on the platform at any time The case where test case data of lid, very intuitively.It is managed collectively and ties up by the test case data to unit testing code Shield can intuitively see which the scene that has covered has at present very much, and greatly improve subsequent cell test can Maintainability.
Based on same inventive concept, the embodiment of the present invention also provides a kind of unit testing device, and the implementation of the device can be joined It is realized according to the process of the above method, it is no longer redundant later to repeat place.
As shown in Fig. 2, being the structural schematic diagram for the unit testing device that the embodiment of the present invention three provides, including generation module 100, parsing module 200 and execution module 300 are loaded;Generation module 100 is used to obtain the lower survey inputted of active cell test Object is tried, each category information corresponding with test object and method information are obtained by reflex mechanism, believed successively according to each class Breath and method information test code according to preset rules and pre-set code template generation unit 120;Unit testing code includes group Close straw line key information;Load parsing module 200 is used to load associated configuration from database according to combination straw line key information and arrange Table, and configured list is parsed, obtain test case data;Execution module 300 is used to be successively read all tests and uses Number of cases evidence, and execution unit 320 tests code, and test report is generated according to implementing result.
The present invention not only realizes that automatically generating unit 120 tests code, greatly improves the exploitation effect of unit testing code Rate;And associated configured list is loaded from database can realize the automatic of unit testing by combining straw line key information Change, avoid test errors caused by human factor, improves testing efficiency and accuracy rate.
As shown in figure 3, for the structural schematic diagram of load parsing module 200;It includes loading unit to load parsing module 200 210, judging unit 220, changing unit 230 and replacement unit 240;Loading unit 210 is used for according to combination straw line key information It is loaded from local data base and associated list and local version information is locally configured;Judging unit 220 is used for obtaining test The current version information of example, judgement is compared by local version information with current version information;If changing unit 230 is for this Ground version information is consistent with the version of current version information, then list will be locally configured and be changed to configured list;Replacement unit 240 If inconsistent for local version information and the version of current version information, according to combination straw line key information from Cloud Server Load associated high in the clouds configured list and high in the clouds version information in database, and by high in the clouds configured list and high in the clouds version information into Row storage replaces in local data base list and local version information is locally configured respectively.
In order to improve operational efficiency, generation module 100 includes limiting unit 110 and generation unit 120;Limit unit 110 For carrying out suffix restriction processing to each category information according to preset rules, meanwhile, according to preset rules to each method information Carry out prefix restriction processing;Generation unit 120 is for each category information that will limit that treated successively and corresponding with category information Method information carries out execution processing according to pre-set code template, and generation unit 120 tests code;Pre-set code template includes into ginseng It converts rigging, execute test method template and outcome expectancy contrast mould.
Further, execution module 300 includes reading unit 310 and execution unit 320;Reading unit 310 is for successively Read all test case datas, each test case data include use-case enter parameter according to, external call analogue data and Execute expected results;Execution unit 320 is used to enter parameter evidence and external call analogue data to unit testing according to each use-case Code carries out execution processing, is compared according to implementing result and execution expected results, and test report is generated according to comparison result.
In order to realize unified management, convenient for safeguarding, the unit testing device that the embodiment of the present invention four provides, with embodiment three It compares, further includes typing management module 400;The test that typing management module 400 is used to input in the case where obtaining active cell test Before object, obtain corresponding with method information with the category information of all kinds of objects to be tested and corresponding method information, and acquisition Use-case enters parameter evidence and external call analogue data;It will be in all kinds of category informations and corresponding method data input Cloud Server; When typing, adds use-case corresponding with method information and enter parameter evidence, external call analogue data and execute expected results, generate Configured list, configured list including test case data with combine the associated key-value pair information of straw line key information and current version This information.
Although the invention has been described by way of example and in terms of the preferred embodiments, but it is not for limiting the present invention, any this field Technical staff without departing from the spirit and scope of the present invention, may be by the methods and technical content of the disclosure above to this hair Bright technical solution makes possible variation and modification, therefore, every content without departing from technical solution of the present invention, and according to the present invention Technical spirit to any simple modifications, equivalents, and modifications made by above example, belong to technical solution of the present invention Protection domain.

Claims (10)

1. a kind of unit test method, which is characterized in that include the following steps;
The lower test object inputted of active cell test is obtained, is obtained by reflex mechanism corresponding with the test object each Category information and method information are given birth to according to each category information and method information according to preset rules and pre-set code template successively At unit testing code;The unit testing code includes combination straw line key information;
Associated configured list is loaded from database according to the combination straw line key information, and the configured list is solved Analysis, obtains test case data;
All test case datas are successively read, and execute the unit testing code, is generated and is surveyed according to implementing result Examination report.
2. unit test method as described in claim 1, which is characterized in that it is described according to the combination straw line key information from number According to associated configured list is loaded in library, include the following steps;
It is loaded from local data base according to the combination straw line key information and associated list and local version information is locally configured;
The current version information for obtaining test case, the local version information is compared with the current version information and is sentenced It is disconnected;
If the local version information is consistent with the version of current version information, list will be locally configured and be changed to configure List;
If the version of the local version information and the current version information is inconsistent, according to the combination straw line key information Load associated high in the clouds configured list and high in the clouds version information from the database of Cloud Server, and by the high in the clouds configured list It is stored with high in the clouds version information, replaces list and local version information is locally configured described in local data base respectively.
3. unit test method as described in claim 1, which is characterized in that described successively according to each category information and side Method information includes the following steps according to preset rules and pre-set code template generation unit testing code;
Suffix restriction processing is carried out to each category information according to the preset rules, meanwhile, according to the preset rules to each Method information carries out prefix restriction processing;
Each category information that will limit that treated successively and method information corresponding with category information are carried out according to pre-set code template Processing is executed, generation unit tests code;The pre-set code template includes into ginseng conversion rigging, executes test method mould Plate and outcome expectancy contrast mould.
4. unit test method as described in claim 1, which is characterized in that described to be successively read all test cases Data, and the unit testing code is executed, generate test report according to the expected results in implementing result and test case data It accuses, includes the following steps;
All test case datas are successively read, each test case data includes that use-case enters parameter evidence, outside It calls analogue data and executes expected results;
Enter parameter evidence and external call analogue data according to each use-case and execution processing carried out to the unit testing code, It is compared according to implementing result and execution expected results, test report is generated according to comparison result.
5. the unit test method as described in claim 1-4 any one, which is characterized in that further comprising the steps of;
In the case where obtaining active cell test before the test object that inputs, obtain and the category information of all kinds of objects to be tested and corresponding Method information, and obtain corresponding with the method information use-case and enter parameter evidence and external call analogue data;
It will be in all kinds of category informations and corresponding method data input Cloud Server;In typing, addition is believed with the method It ceases the corresponding use-case to enter parameter evidence, external call analogue data and execute expected results, generation includes test case number According to configured list, configured list with combine the associated key-value pair information of straw line key information and current version information.
6. a kind of unit testing device, which is characterized in that including generation module, load parsing module and execution module;
The generation module, for obtaining the lower test object inputted of active cell test, by reflex mechanism obtain with it is described The corresponding each category information of test object and method information, successively according to each category information and method information according to default rule Then with pre-set code template generation unit testing code;The unit testing code includes combination straw line key information;
The load parsing module, for loading associated configured list from database according to the combination straw line key information, And the configured list is parsed, obtain test case data;
The execution module for being successively read all test case datas, and executes the unit testing code, root Test report is generated according to implementing result.
7. unit testing device as claimed in claim 6, which is characterized in that the load parsing module include loading unit, Judging unit, changing unit and replacement unit;
For being loaded from local data base according to the combination straw line key information associated row are locally configured in the loading unit Table and local version information;
The judging unit, the current version information for obtaining test case, by the local version information with it is described current Judgement is compared in version information;
The changing unit will be local if consistent with the version of current version information for the local version information Configured list is changed to configured list;
The replacement unit, if the version for the local version information and the current version information is inconsistent, basis The combination straw line key information loads associated high in the clouds configured list and high in the clouds version information from the database of Cloud Server, and The high in the clouds configured list and high in the clouds version information are stored, replaces list is locally configured described in local data base respectively With local version information.
8. unit testing device as claimed in claim 6, which is characterized in that the generation module includes limiting unit and generation Unit;
The restriction unit, for carrying out suffix restriction processing to each category information according to the preset rules, meanwhile, according to institute It states preset rules and prefix restriction processing is carried out to each method information;
The generation unit, for will limit that treated successively each category information and method information foundation corresponding with category information Pre-set code template carries out execution processing, and generation unit tests code;The pre-set code template includes die-filling into conversion group is joined Plate executes test method template and outcome expectancy contrast mould.
9. unit testing device as claimed in claim 6, which is characterized in that the execution module includes reading unit and execution Unit;
The reading unit, for being successively read all test case datas, each test case data includes Use-case enters parameter evidence, external call analogue data and executes expected results;
The execution unit, for entering parameter evidence and external call analogue data to the unit testing according to each use-case Code carries out execution processing, is compared according to implementing result and execution expected results, and test report is generated according to comparison result.
10. the unit testing device as described in claim 6-9 any one, which is characterized in that further include typing management module;
The typing management module, for before the test object inputted under obtaining active cell test, acquisition to be waited for all kinds of The category information of test object and corresponding method information, and obtain use-case corresponding with the method information and enter parameter evidence and outside Call analogue data;
It will be in all kinds of category informations and corresponding method data input Cloud Server;In typing, addition is believed with the method It ceases the corresponding use-case to enter parameter evidence, external call analogue data and execute expected results, generation includes test case number According to configured list, configured list with combine the associated key-value pair information of straw line key information and current version information.
CN201810455233.9A 2018-05-14 2018-05-14 Unit testing method and device Active CN108595342B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810455233.9A CN108595342B (en) 2018-05-14 2018-05-14 Unit testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810455233.9A CN108595342B (en) 2018-05-14 2018-05-14 Unit testing method and device

Publications (2)

Publication Number Publication Date
CN108595342A true CN108595342A (en) 2018-09-28
CN108595342B CN108595342B (en) 2021-09-14

Family

ID=63637118

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810455233.9A Active CN108595342B (en) 2018-05-14 2018-05-14 Unit testing method and device

Country Status (1)

Country Link
CN (1) CN108595342B (en)

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109753428A (en) * 2018-12-13 2019-05-14 浙江数链科技有限公司 Service test method, device, computer equipment and readable storage medium storing program for executing
CN110750457A (en) * 2019-10-21 2020-02-04 中国民航信息网络股份有限公司 Automatic unit testing method and device based on memory database
CN111078555A (en) * 2019-12-16 2020-04-28 深圳市朱墨科技有限公司 Test file generation method, system, server and storage medium
CN111522741A (en) * 2020-04-14 2020-08-11 北京奇艺世纪科技有限公司 Interface test code generation method and device, electronic equipment and readable storage medium
CN111767217A (en) * 2020-06-24 2020-10-13 中国工商银行股份有限公司 JS unit test case generation method and device
CN112363942A (en) * 2020-11-17 2021-02-12 浪潮云信息技术股份公司 System and method for realizing reusable unit test
CN112416742A (en) * 2019-12-27 2021-02-26 上海哔哩哔哩科技有限公司 Automatic generation method of JMeter test script, interface test method and system
CN112882931A (en) * 2021-02-06 2021-06-01 重庆富民银行股份有限公司 Automatic testing method and device based on DDT
CN113467761A (en) * 2021-06-03 2021-10-01 上海赛可出行科技服务有限公司 Interface test template generation method based on Java reflection principle
CN113760745A (en) * 2021-05-19 2021-12-07 北京沃东天骏信息技术有限公司 Interface automation test case generation method and device
CN114416536A (en) * 2021-12-29 2022-04-29 江苏康众汽配有限公司 Integrated unit testing method and system based on SpringBoot
CN114528214A (en) * 2022-02-18 2022-05-24 马上消费金融股份有限公司 Unit testing method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101026503A (en) * 2006-02-24 2007-08-29 国际商业机器公司 Unit detection method and apparatus in Web service business procedure
US20090125877A1 (en) * 2007-10-22 2009-05-14 Oracle International Corporation Extensible code visualization
CN102760096A (en) * 2011-04-27 2012-10-31 阿里巴巴集团控股有限公司 Test data generation method, unit testing method and unit testing system
CN104407973A (en) * 2014-11-25 2015-03-11 珠海格力电器股份有限公司 Method and device for realizing automatic unit test

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101026503A (en) * 2006-02-24 2007-08-29 国际商业机器公司 Unit detection method and apparatus in Web service business procedure
US20090125877A1 (en) * 2007-10-22 2009-05-14 Oracle International Corporation Extensible code visualization
CN102760096A (en) * 2011-04-27 2012-10-31 阿里巴巴集团控股有限公司 Test data generation method, unit testing method and unit testing system
CN104407973A (en) * 2014-11-25 2015-03-11 珠海格力电器股份有限公司 Method and device for realizing automatic unit test

Cited By (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109753428A (en) * 2018-12-13 2019-05-14 浙江数链科技有限公司 Service test method, device, computer equipment and readable storage medium storing program for executing
CN110750457A (en) * 2019-10-21 2020-02-04 中国民航信息网络股份有限公司 Automatic unit testing method and device based on memory database
CN110750457B (en) * 2019-10-21 2023-11-10 中国民航信息网络股份有限公司 Automatic unit testing method and device based on memory database
CN111078555A (en) * 2019-12-16 2020-04-28 深圳市朱墨科技有限公司 Test file generation method, system, server and storage medium
CN111078555B (en) * 2019-12-16 2024-04-23 深圳市朱墨科技有限公司 Test file generation method, system, server and storage medium
CN112416742A (en) * 2019-12-27 2021-02-26 上海哔哩哔哩科技有限公司 Automatic generation method of JMeter test script, interface test method and system
CN111522741A (en) * 2020-04-14 2020-08-11 北京奇艺世纪科技有限公司 Interface test code generation method and device, electronic equipment and readable storage medium
CN111522741B (en) * 2020-04-14 2023-11-14 北京奇艺世纪科技有限公司 Interface test code generation method and device, electronic equipment and readable storage medium
CN111767217A (en) * 2020-06-24 2020-10-13 中国工商银行股份有限公司 JS unit test case generation method and device
CN111767217B (en) * 2020-06-24 2024-02-02 中国工商银行股份有限公司 JS unit test case generation method and device
CN112363942A (en) * 2020-11-17 2021-02-12 浪潮云信息技术股份公司 System and method for realizing reusable unit test
CN112882931B (en) * 2021-02-06 2023-05-09 重庆富民银行股份有限公司 Automatic test method and device based on DDT
CN112882931A (en) * 2021-02-06 2021-06-01 重庆富民银行股份有限公司 Automatic testing method and device based on DDT
CN113760745A (en) * 2021-05-19 2021-12-07 北京沃东天骏信息技术有限公司 Interface automation test case generation method and device
CN113467761A (en) * 2021-06-03 2021-10-01 上海赛可出行科技服务有限公司 Interface test template generation method based on Java reflection principle
CN113467761B (en) * 2021-06-03 2024-06-14 上海赛可出行科技服务有限公司 Interface test template generation method based on Java reflection principle
CN114416536A (en) * 2021-12-29 2022-04-29 江苏康众汽配有限公司 Integrated unit testing method and system based on SpringBoot
CN114416536B (en) * 2021-12-29 2024-07-30 江苏康众汽配有限公司 SpringBoot-based integrated unit testing method and SpringBoot-based integrated unit testing system
CN114528214A (en) * 2022-02-18 2022-05-24 马上消费金融股份有限公司 Unit testing method and device

Also Published As

Publication number Publication date
CN108595342B (en) 2021-09-14

Similar Documents

Publication Publication Date Title
CN108595342A (en) Unit test method and device
CN106649103B (en) A kind of method and system of Android application program Automated Black Box Testing
CN106446412B (en) Model-based test method for avionics system
CN106909510A (en) A kind of method and server for obtaining test case
CN111522734B (en) Software function testing method and device, electronic equipment and storage medium
CN111782266B (en) Software performance benchmark determination method and device
CN107741903A (en) Application compatibility method of testing, device, computer equipment and storage medium
CN112433944A (en) Service testing method, device, computer equipment and storage medium
CN110109829B (en) Intelligent dialogue automatic checking method and storage medium
US11663113B2 (en) Real time fault localization using combinatorial test design techniques and test case priority selection
CN111752841A (en) Single test simulation method, device, equipment and computer readable storage medium
CN113535141A (en) Database operation code generation method and device
CN112561690B (en) Method, system, equipment and storage medium for testing credit card staged service interface
CN116266117A (en) Model conversion method, computer program product, storage medium, and electronic device
CN116956801B (en) Chip verification method, device, computer equipment and storage medium
CN117034816A (en) Register mapping method and device based on system level verification scene
CN116561003A (en) Test data generation method, device, computer equipment and storage medium
CN116090252A (en) Matlab-based method, device, equipment and medium for automatically generating input interface model
EP3734491A1 (en) Method, apparatus, device, and medium for implementing simulator
CN118261143B (en) Json data analysis method, device, equipment and medium in Unity environment
CN115840715B (en) Software test management method, device and storage medium
CN117687608B (en) Method, device, equipment and storage medium for generating orchestration stream
CN114756217B (en) Plug-in based script generation system
CN115982055B (en) Test method special for java language development program
CN112597026B (en) Test case generation method and device

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
GR01 Patent grant
GR01 Patent grant