# Patent

## Title
System and method for generating coverage reports for software unit tests

## Abstract

A unit test coverage report system and method may generate a coverage report to indicate the success or failure of current unit tests and the amount of further testing that is required to fully test an application undergoing development. The system or method may receive a source code file including a plurality of source code units, wherein each source code unit corresponds to one of a plurality of comments sections. The system or method may then parse the plurality of comments sections and extract an identification of each source code unit from the plurality of comments sections. The identification may then be compared to a list of tested source code units and the comparison added to a unit test coverage report.

## Background
TECHNICAL FIELD
The present disclosure generally relates to a system and method for generating a report related to unit testing during software development and, more particularly, to generating a coverage report to indicate the success or failure of current unit tests and the amount of further testing that is required to fully test an application.
BACKGROUND
Software programs or applications typically include several different functions, modules, methods, etc. (i.e., “units”) that interact by accessing and using shared resources. Generally speaking, a unit may be described as the smallest testable portion of an application such as a function or procedure. On a larger scale, applications themselves are written so that other programs may be written to access and use the application's resources. To understand existing applications and to develop new applications that add functionality to these existing applications, an application programming interface (API) is often developed to aid future development. An API defines the rules and specifications for a software program so that other programs can be designed to use the various resources of that program. In other words, the API operates as an interface between programs.
To assist other programmers in creating compatible programs, each application typically includes an API while the source code for each unit within the application includes comments that describe the unit. For example, the comments may generally describe the classes, methods and objects within a unit of the source code as well as the inputs and outputs expected during that unit's execution. In conjunction with the API, these unit comments may guide developers as they write compatible applications or expand the application.
However, an API may be difficult and time-consuming to write. As the complexity of the source code grows, an API accessing the source code will also become more complex. Numerous systems may automatically generate APIs and other documentation in a common format (e.g., HTML) directly from the API's source code. For example, commercial tools like Javadoc (“JDoc”) from Oracle Corporation, or open source tools such as JSDoc and Doxygen parse the source code and source code comments into hyperlinked HTML API documents.
In addition to the API, testing is often necessary to develop effective and efficient computer code. The process of testing code typically includes, but is not limited to, testing units of the application in isolation from the other units of the application as the programmer writes the source code for the application. Testing normally involves writing a short test application that utilizes the code that is the subject of the test. This short application includes a rigorous contract that the test subject source code must satisfy when it is executed. If the test is written correctly and the contract is satisfied, then the developer is more confident that the test subject source code will perform correctly for any other user or developer. Testing usually proceeds in isolation for each unit of the source code to reduce the likelihood that one developer creates the same error in both the implementation and the test application. Further, if all units of an application pass the unit tests in isolation, then the application as a whole is more likely to execute as desired when all units are included.
While several tools exist to automatically write an API for a finished application, unit tests are written by the developer in the same manner as the source code, often while the source code for the unit is written, or at some time after the source code is finished. As an application increases in complexity, the number of unit tests required increases. Because developers must write each unit test in the same manner as the source code, unit testing becomes a tedious and complex process for even the simplest of applications. Understanding whether testing for complex applications that include many testable units is successful or complete can also be confusing and time consuming.
SUMMARY
A unit test coverage report system, a computer-implemented method, or a tangible computer readable medium may cause a processor to receive a source code file including a plurality of source code units, wherein each source code unit corresponds to one of a plurality of comments sections. The system, method, or medium may then cause a processor to parse the plurality of comments sections and extract an identification of each source code unit from the plurality of comments sections. The system, method, or medium may then cause a processor to compare the identification to a list of tested source code units, and then add the comparison to a unit test coverage report.
In another embodiment, a computer system may comprise several modules for generating a unit test coverage report. For example, a source code database interface module may be configured to store in a database a plurality of source code files, each file including a plurality of source code units, wherein each source code unit corresponds to one of a plurality of comments sections. Further, a unit test generator module may be configured to read the plurality comments sections, to parse the plurality of comments sections, and extract an identification of each source code unit from the plurality of comments sections. Also, a report module may be configured to compare the identification to a list of tested source code units and add the comparison to a unit test coverage report.
Another embodiment includes a computer-implemented method for generating a unit test coverage report that receives a source code file including a plurality of source code units and a plurality of comments sections, the comments sections each including a source code unit name and a source code unit description. The method may then parse the plurality of comments sections to determine a source code unit type corresponding to a source code unit description and to determine the plurality of source code unit names and extract both the plurality of source code unit description and the plurality of source code unit names from the plurality of comments sections. After extracting the unit description, the method may copy the unit description to a unit test stub corresponding to the source code unit type. Further, the method may receive additional code to transform each unit test stubs into a plurality of unit tests for each of the plurality of source code units, execute the plurality of unit tests, and generate a test result indication for each unit test. After executing the tests, the method may compare the plurality of source code unit names to a list of tested source code units and adding the comparison to a unit test coverage report.
The features and advantages described in this summary and the following detailed description are not all-inclusive. Many additional features and advantages will be apparent to one of ordinary skill in the art in view of the drawings, specification, and claims hereof.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 illustrates a block diagram of an exemplary unit testing system in accordance with the described embodiments;
FIG. 2 illustrates an example text representation of code within a source code file in accordance with the described embodiments;
FIG. 3 illustrates an example text representation of unit test stubs and unit tests generated by the unit testing system in accordance with the described embodiments;
FIG. 4a illustrates an example unit test report in accordance with the described embodiments;
FIG. 4b illustrates another example unit test report in accordance with the described embodiments;
FIG. 5 illustrates an exemplary block diagram of a method for using the unit testing system in accordance with the described embodiments; and
FIG. 6 illustrates a high-level block diagram of a computing environment that implements modules of the unit test generator in accordance with the described embodiments.



The figures depict a preferred embodiment of the present invention for purposes of illustration only. One skilled in the art will readily recognize from the following discussion that alternative embodiments of the structures and methods illustrated herein may be employed without departing from the principles of the invention described herein.
DETAILED DESCRIPTION
FIG. 1 illustrates a block diagram of a high-level architecture of a unit test generation system 100 including various software and hardware components or modules that may be employed to automatically generate unit tests for source code using comments written into the source code. The various modules may be implemented as computer-readable storage memories containing computer-readable instructions (i.e., software) for execution by a processor of a computer system. The modules may perform the various tasks associated with generating unit tests from source code files, as herein described. The system 100 also includes both hardware and software applications, as well as various data communications channels for communicating data between the various hardware and software components.
A developer 102 may write source code 104 for a computer program using a general text editing program (e.g., notepad, WordPad®, etc.), an integrated development environment (IDE) (e.g., NetBeans®, CodeLite, JBuilder®, etc.), or other program executing on a computing device. The developer 102 may store the source code 104 within a local or remote database 106 as a text file or type of file. In some embodiments, the database 106 is a component of a server 108 or other computing device including both a processor 108a and memory 108b. FIG. 2 illustrates one example of a portion of source code 104, in particular, a comments section 200 of a source code file 104. A comments section 200 includes text that is ignored by source code compilers and interpreters, but may provide useful information to developers who edit, optimize, or use the source code 104. The information in the comments portions 200 may make the source code 104 easier to understand for developers 104 to write other code that is compatible with the source code 104. Each programming language's specification includes syntax and rules for using comments so that the text is ignored during compilation or interpretation. For example, both Java® and C-based languages use a double forward slash (“//”) or a forward slash and asterisk combination (“/***/”) notation as illustrated by FIG. 2. As a Java or C compiler or interpreter parses a line of code beginning these particular characters, the compiler or interpreter will ignore that line of code.
In some embodiments, the comments section 200 includes and example section 202 within the comments section. The example section 202 may include a unit description 204 (e.g., a method description, a member variable description, or other text) that may be useful in an API corresponding to the source code file. For example, the unit description 204 may include a portion of code that, if executed, would provide expected results from a function, method, class, or other unit of code from the source code file. As illustrated by FIG. 3, the unit description 204 provides code to determine an expected result from the “Vector3d.linear_combination” method 205. The comments section may also include a beginning keyword and an ending keyword as well as additional text portions further describing the method 205 and the unit description 204 of the example section 202 (e.g., additional comments 212 and 214). Each unit description 204 may also correspond to a unit of source code (i.e., the smallest testable portion of the application encoded in the source code file 104).
Returning to FIG. 1, the a unit test generation system 100 may also include several components or software modules and instructions stored in a computer-readable storage memory and executed on a processor (e.g., 108b and 108a or similar structures within a local computer user by the developer 102) to generate unit tests using one or more comments sections 200 within a source code file 104. In some embodiments, a module or component organizes and formats the source code, and generates unit test stubs (called the unit test generator module 110 or “ourdoc” module 110). In some embodiments, the ourdoc module 110 includes one or more instructions stored in a computer-readable storage memory and executed on a processor to access the database 106 or other data storage and retrieve a source code file 104 that includes one or more comments portions 200. Alternatively, the ourdoc module 110 receives a source code file 104 or a portion of the source code file 104 including one or more comments sections 200. The ourdoc module 110 may also include one or more instructions stored in a computer-readable storage memory and executed on a processor to convert the source code file 104 into another format for analysis. For example, the ourdoc module 110 may convert the file 104 into a stream of text or other data (e.g., serialize the file 104), search through the stream of text, and either break it up into useful chunks of information (i.e., tokens) or reformat the file 104 for analysis.
The ourdoc module 110 may also include one or more instructions stored in a computer-readable storage memory and executed on a processor to identify a comment section 200 within the source code file 104 and output one or more files using the comment section 200 as input. In some embodiments, the ourdoc module 110 identifies notation within the source code file 104 that indicates a comment section 200. For example, the ourdoc module 110 may identify any line of text within the source code file 104 beginning with “//” or “/*...*/” notation as a portion of a comment section 200. Once the ourdoc module 110 identifies comment notation, then the text within the comment section 200 may be further analyzed. For example, the ourdoc module 110 may include one or more instructions stored in a computer-readable storage memory and executed on a processor to identify a particular character or token within the comments section that may be passed as an argument to another instruction stored in a computer-readable storage memory and executed on a processor.
The comments section 200 may be formatted in an industry standard that permits developers to quickly write comments so that they may be used to create public documentation. In some embodiments, the comments section 200 is written in the “Doxygen” format. For example, a particular character (e.g., an “@” character, a “%” character, etc.) and name combination (i.e., a command or keyword) within the comments section 200 may indicate that text following that character has particular meaning to create public documentation, unit tests, etc. One example of a command or keyword 212 includes “@version” and text following this keyword may include “SketchUp 6.0” to indicate that the comments section 200 corresponds to version six of the SketchUp application. Following the Doxygen format, the ourdoc module 110 may include one or more instructions stored in a computer-readable storage memory and executed on a processor to create public documentation. In some embodiments, the public documentation is an HTML, XML, or other type of uniformly-formatted document that describes the classes, class hierarchy, class members, etc., that correspond to the various classes listed in the comments section 200.
The ourdoc module 110 may also extend the Doxygen format to include keywords that are used to create unit tests. For example, the ourdoc module 110 may define various commands and keywords to extend Doxygen functions. In one embodiment, a “@par Example” ourdoc command 206 may be read and used as an input to a method of the ourdoc module 110 to indicate the beginning of comments that describe an ideal execution of the source code. Further, comments following the “@par Example” keyword may include Doxygen keywords and commands that may be read and used as an input to other methods of the ourdoc module 110. For example, “@code” and “@endcode” Doxygen commands may be used by both Doxygen and ourdoc module 110 methods to produce different results. As used by Doxygen, a block of comments beginning with a “@code” 208 command and ending with a “@endcode” command 210 may produce a public documentation file wherein Doxygen interprets the comments within the example section 202 as code. Within the Doxygen-produced public documentation file, the names of the classes and members that are documented within the unit description 204 will be replaced by references to the documentation for those particular classes and members.
The ourdoc module 110 may include one or more instructions stored in a computer-readable storage memory and executed on a processor to use the “@code” and “@endcode” commands as a signal to create unit tests for the classes and members described in the comments that follow the “@code” command and are before the “@endcode” command (i.e., the unit description 204). With further reference to FIG. 3, the ourdoc module 110 may include instructions to generate unit test stubs 300 from the example section and store the stubs within a unit test suite 112. In some embodiments, a unit test stub 300 consists of a declaration of a testing routine 301 and input and output parameters accepted by the testing routine 204. The unit test stubs 300 may be used as placeholders for routines that need to be developed to fully test the source code. For example, the unit test stubs 300 may include only enough code to allow the stubs 300 to be compiled and linked with the rest of the unit test suite 112. Additional functionality may be added to the stubs 300 by adding more code. In some embodiments, the ourdoc module 110 copies the unit description 204 into a unit test stub 300, wherein the parameters accepted by the testing routine of the stub 300 include at least the unit description 204. Further, a developer 102 or another module or routine may add more code to the stubs 300 to augment the unit test.
The unit test suite 112 may include all of the unit tests for an application. The ourdoc module 110 may generate a variety of unit tests for the unit test suite 112 from each unit description 204 such that the tests represent the various categories of common coding problems and the tests cover a high degree of execution results for the source code file 104. For example, the ourdoc module 110 may create unit test stubs for trivial source code cases, but also for other categories of method and member inputs such as boundaries, bad input types, random inputs, negative tests, etc.
The ourdoc module 110 may also analyze the unit description 204 to determine to what type of function the unit description 204 corresponds. For example, the unit description 204 may correspond to parameters of a “setter” function (i.e., source code expressions that establish a value such as “var=2”), a “getter” function (i.e., source code expressions that retrieve an established value such as “return var”), or other type of function in the source code for which a unit test is desired. After determining what type of function corresponds to the unit description 204, the ourdoc module 110 may include one or more instructions stored in a computer-readable storage memory and executed on a processor to generate a unit test stub 300 corresponding to the function type (i.e., a setter unit test, a getter unit test, etc.). For example, when the ourdoc module 110 serializes or tokenizes and parses the unit description 204, the ourdoc module 110 may identify a “=” symbol corresponding to a “setter” function. Once identified as a setter function, the ourdoc module 110 may generate setter unit tests. When the ourdoc module 110 identifies the word “return”, which corresponds to a “getter” function, the module 110 may generate getter unit tests. Of course, the ourdoc module 110 may include other instructions to identify and generate other types of unit tests depending on particular symbols, words, commands, keywords, etc., the module 110 identifies within the unit description 204.
Regardless of the type of unit tests the module 110 generates, each set of unit tests may include at least a trivial test of the unit description 204 that is generated from the comment section 200 and other categories of unit tests. With reference to FIG. 3, the test stubs 300 may include a trivial unit test 302, a boundary or “edge case” unit test 304, a bad parameters unit test 306, and other unit tests (e.g., random inputs, negative tests, etc.). Depending on the type of unit tests identified (e.g., setter or getter unit tests, etc.), the test stubs 300 may include different instructions corresponding to the type of unit in the unit description 204. For example, if the ourdoc module 110 identifies the unit description 204 as a “setter”, then instructions of the module 110 may generate a trivial unit test 302 having commands corresponding to the “setter” instructions of the comments section 200. The commands may correspond to typical “raise” 304 and “assert” 306 commands to test the setter method from the unit description 204 of the comments section 200. For example, the assert command 306 for the setter method from the source code file 104 corresponding to the unit description 204 tests if the “expected” value and the “result” value of the “new_vector” variable are equal. If the expected and actual values are not equal, then the unit test fails. Further, the assert command for a getter method from a unit description may test if the returned parameter is the same type as the expected parameter. If the expected and returned types are not equal, then the unit test fails. In any case, if the expected and actual values of a tested variable (i.e., the “new_vector” variable illustrated in FIGS. 2 and 3 or any other variable) are equal, then the unit test succeeds.
In some embodiments, the ourdoc module 110 may automatically add a test stub 300 to check the ability of the function to generate an expected type of error when executed. For example, when the ourdoc module 110 analyzes the unit description 204 and identifies it as a getter function, the test stub 300 for a “get_coordinates” function may apply an invalid coordinate point as an input to the function to ensure that an “Exception::ArgumentError” would be received, as expected. In contrast, when the ourdoc module 110 identifies a function as a setter, different kind of errors may be expected depending on what the function sets. For Example, an “Exception::TypeError” error may be expected from a “set_coordinates” function that, when executed, receives a “string” type input when the function only accepts an “integer” type input.
In other embodiments, the ourdoc module 110 may identify setter or getter functions that return Boolean values and generate an appropriate test stub 300. For example, the ourdoc module 110 may identify a Boolean getter function within the unit description 204 with a particular character (e.g., a character such as “MyClass.is_visible?”). The ourdoc module 110 may then output a test stub 300 for the Boolean getter to ensure the function result is not null (i.e., a stub “result_is_not_null( )”) and that the result is one of “true” or “false” (i.e., a stub “result_is_true_or_false( )”). Of course, the ourdoc module 110 may include instructions to generate other types of unit tests that are specific to the function type, such as testing that a parameter was correctly set by a setter function or that a getter function correctly retrieves the expected type of parameter, random inputs, negative tests, etc.
As indicated in FIG. 3, each of the unit test stubs 300 includes comments within a raise command 304, 312, 314. These comments may be automatically generated with the unit test stubs 300. In some embodiments, the comments within the raise commands 304, 312, 314 may indicate to a developer that further action should be taken to complete each unit test 302, 308, 310 so that the unit test stubs 300 may be completed so that each unit of the source code file 104 is properly tested and the unit test stubs 300 form complete unit tests. For example, a developer 102 may add code to each unit test stub 300 so that the stub 300 represents a complete unit test corresponding to a unit of the source code file 104. Of course, another module (e.g., the ourdoc module 110) may also automatically add code to each unit test stub 300 and transform each stub 300 into a complete unit test corresponding to a unit of the source code file 104. Each unit may be properly tested when it passes its unit tests including at least a unit test corresponding to its description 204, boundaries unit tests, and bad input unit tests. These comments may be deleted by the developer to indicate when the developer has completed a review of the unit tests 302, 308, 310. In further embodiments, the developer may edit (i.e., add, delete, or change) the text of the unit tests 302, 308, and 310 so that each unit is properly tested.
Again referring to FIG. 1, a module 114 may test each of the unit tests 302, 308, 310 within the unit test suite 112. The module or “test harness” 114 may determine whether the unit tests have been properly completed for each unit identified within the corresponding source code file 104. In some embodiments, a module entitled “TestUp” may serve as the unit test harness 114. The TestUp module may be external to the application represented by the source code 104. In further embodiments, the TestUp module 114 may simulate services or functions that are not available in the test environment. For example, where the application represented by the source code 104 is an internet-deployed application requiring one or more web servers, the TestUp module 114 may include functions or routines that simulate web server communication such that the units of the source code 104 may be properly tested. Likewise, the TestUp module 114 may generally provide an environment in which all units of the source code 104 are properly tested. In some embodiments, the TestUp module 114 runs each unit test as it is created within the unit test suite 112 to determine how much of the source code file 104 is properly tested. The TestUp module 114 may provide a test result indication (e.g., a pass, fail, or follow up indication) 316 for each unit test within the unit test suite 112.
After testing each completed unit test 300 within the unit test suite 112, the ourdoc module 110, the TestUp module 114, a reporting module 117, or another module may generate unit test coverage reports 116a and 116b. The reports 116a and 116b may provide an indication of how much source code file 104 testing is complete and may also modify the unit test stubs 300 to indicate whether a particular unit test passed, failed, or needs further development. For example, if a unit test passes after being executed by the TestUp module 114, then the text corresponding to that passed test 302 within the unit test suite 112 may be highlighted in green or another indication. Likewise, if a unit test requires follow up 308 after being executed by the TestUp module 114, then the text corresponding to that test within the unit test suite 112 may be highlighted in yellow or another indication. Also, if a unit test fails 310 after being executed by the TestUp module 114, then the text corresponding to that failed test within the unit test suite 112 may be highlighted in red or another indication. Text or another indication may also be inserted into the unit tests 300 after execution by the TestUp module 114 indicating pass 316, follow up 318 or fail 320.
The unit test coverage reports 116a and 116b may also include an indication of how thoroughly and effectively the unit test suite 112 tests the units identified within the source code file 104. In some embodiments, the reports 116a and 116b may be an output of the TestUp module 114 or the ourdoc module 110, or a reporting module 117. The reports 116a and 116b may be sent to the developer 102 and include several indications about the source code 104 and the unit testing process. For example, the unit test reports 116a and 116b may include an indication of whether each unit test (e.g., unit tests 302, 308, 310) properly tests its corresponding source code unit (the parameters of which are described in the comments section 200 of the source code file 104), an indication of how many of the total number of unit tests described within the comments sections 200 of the source code file 104 are properly tested, and a coverage measure indicating how much of the testing process is complete, to name only a few of the indications that may be available in the reports 116a and 116b. 
In some embodiments, a reporting module 117 may extract a list of source code units (e.g., the names of the classes and methods) from the comments sections 200 of the source code file 104 and correlate that list with the number of unit tests that passed when executed by the TestUp module 114 to determine a measure of testing coverage 402 For example, the reporting module 117 may parse the comments sections 200 of a source code file 104 to extract each method name 205 or class name, and copy each extracted method or class name to a list. The reporting module 117 may then compare the list of methods and classes against the method and classes tested by the TestUp module 114. The TestUp module 114 may create a list of classes and methods it tests as the tests are run and provide that list to the reporting module 117. The reporting module may then compare the lists to the indication of whether each particular unit test passed to generate a measure of testing coverage 402 for each class. The coverage measure 402 may generally describe how many units within a class are covered by unit tests that pass or succeed. For example, a report indicating sixty-eight percent test coverage may specify that, of a total of one hundred functions within a class, sixty-eight of those functions are tested properly and pass those tests (i.e., the unit test suite 112 includes unit tests that pass for sixty eight of one hundred total units within the class).
With reference to FIG. 5, the unit test generator system 100 described herein may be employed in a method 500 (FIG. 5) to generate unit tests for a source code file. The method 500 may include one or more functions or routines in the form of computer-executable instructions that are stored in a tangible computer-readable medium and executed using a processor of a computing device (e.g., a computing device being used or accessed by the developer 102). The routines may be included as part of any of the modules described in relation to FIG. 1, or as part of a module that is external to the system illustrated by FIG. 1.
At function 502, the system 100 may execute an instruction to receive a source code file 104. As described above, the source code file 104 may include a text file of computer code including one or more comments sections 200. The source code file may be created by the developer 102 using a general text editing program (e.g., notepad, WordPad®, etc.), an integrated development environment (IDE) (e.g., NetBeans®, CodeLite, JBuilder®, etc.), or other program executing on a computing device. The developer 102 may store the source code 104 within the local or remote database 106 as a text file or type of file, or the system 100 may receive the source code file 104 from an external source. The comments section 200 of the source code file 104 may include one or more unit descriptions 204 and be stored either internally or externally to the system 100.
At function 504, the system 100 may execute an instruction to retrieve a source code file 104 and convert the file 104 into another format for analysis by the system 100. For example, the function 504 may convert the file 104 into a searchable stream of text or other data, break the file 104 up into useful chunks of information (i.e., “tokenize” the source code file), or otherwise reformat the file 104.
At function 506, the system may execute an instruction to identify a comment section 200 and unit description 204 within the source code file 104. For example, using a data stream created at function 504, the function 506 may identify certain text characters that indicate a portion of the source code file 104 that includes the comments section 200, as described above. The unit description 204 may be identified within the comments section 200 by one or more keywords identified within the data stream or tokenized version of the source code file 104.
At function 508, the system 100 may execute an instruction corresponding to a command or keyword (e.g., commands 208 and 210) within the comments section 200. In some embodiments, the system 100 may use the identified command or keyword as a method input to perform another function. For example, if the function 508 identifies a “@code” command 208, then the function 508 may read the text following that command until the function 508 encounters another command to signal the function 508 to stop reading the text (e.g., the “@endcode” command). The “@code” command 208 may also cause the function 508 to serialize or tokenize the text after the command 208 until the “@endcode” command 210 is read. The function 508 may also encounter other commands after an “@code” command. Other commands may signal the function 508 to perform other tasks such that the other commands may be nested between several “@code” and “@endcode” commands. In some embodiments, the text between the “code” and “@endcode” commands includes the unit description 204. The unit description 204 may include a method description, a member variable description, a function, or other text that corresponds to the expected input and output of a unit of code (e.g., the “Vector3d.linear_combination” method 205) from the source code file 104.
At function 510, the system 100 may execute an instruction to identify a function type of the unit description 204 as read, serialized, or tokenized by the function 508 between the “@code” 208 and “@endcode” 210 commands. For example, if the function 510 identifies a “=” symbol within the unit description 204, the function 510 may identify the unit description 204 as a “setter” function. Further, if the function 510 serializes or tokenizes the unit description 204 and identifies the word “return”, the function 510 may identify the unit description 204 as corresponding to a “getter” function. Of course, the function 510 may identify other types of functions depending on particular symbols, words, commands, keywords, etc., the function 510 identifies within the unit description 204.
At function 512, the system 100 may execute an instruction to generate a unit test corresponding to the function type identified by function 510. In some embodiments, the function 512 generates a unit test stub 300 that incorporates text from the comments section 200. For example, the unit test stub 300 may include a portion of the code from the unit description 204. The function 512 may generate other code for the stub 300 as well, such as raise, assert, or other code that corresponds to the type of function identified by function 510. If the function 510 identifies the unit description 204 as a “setter”, then function 512 may generate a unit test 302 having commands corresponding to the “setter” instructions of the comments section 200. The function 512 may generate a plurality of unit tests or unit test stubs 300 corresponding to the typically encountered problems with units of the source code file 104 such as input boundary tests, bad input type tests, random input tests, negative tests, etc.
At function 514, the system 100 may execute an instruction to test each of the unit tests that were generated by function 512. In some embodiments, a test harness such as the TestUp module 114 may run each unit test within the unit test suite 112 to determine how much of the source code file 104 is properly tested. The function 514 may provide a pass, fail, or follow up indication for each unit test within the unit test suite 112.
At function 516, the system 100 may execute an instruction to generate a unit test coverage reports 116a and 116b. As illustrated by FIGS. 4a and 4b, the reports 116a and 116b may include an indication of how much of the testing for the source code file 104 is complete and successful. In some embodiments, the function 516 modifies the appearance of the code within the unit test suite 112 such that a developer 102 or another module may easily determine if a unit test is complete. For example, if a unit test passes, requires follow up, or fails after being executed by the TestUp module 114, then the text corresponding to that test within the unit test suite 112 may be highlighted in green, yellow, red or another indication. The unit test coverage reports 116a and 116b may also include an indication of how thoroughly and effectively the unit test suite 112 tests the units identified within the source code file 104. For example, a unit test coverage report 116a (FIG. 4a) may include a summary section 400 as well as a summary of each unit's testing completion and success by a color or other indication of pass, fail, or follow up needed (e.g., green, red, and yellow, respectively). Further, a unit test report 116b (FIG. 4b) may include an indication of whether each unit test (e.g., unit tests 302, 308, 310) properly tests its corresponding unit 404 (i.e., the comments section 200 of the source code file 104), an indication of how many of the total number of unit tests described within the comments sections 200 of the source code file 104 are properly tested 406, a number that are not properly tested 408, and a coverage measure (for each unit 402 or the entire application 405) indicating how much of the testing process is complete, to name only a few of the indications that may be available in the report 116.
In some embodiments, the reporting module 117 parses the comments sections 200 of a source code file 104 to extract each method name 205 or class name, and copies each extracted method or class name to a list. The reporting module 117 may then compare the list of methods and classes against the method and classes tested by the TestUp module 114. The reporting module 117 may then receive a list of classes and methods that were tested by the TestUp module 114. The reporting module 117 may then compare the lists to the indication of whether each particular unit test passed to generate a measure of testing coverage 402 for each class. As described herein, the coverage measure 402 may generally describe how many units within a class are covered by unit tests that pass or succeed. Further, the report 116 may include a coverage measure of how many units within a class are covered by unit tests that pass.
FIG. 6 is a block diagram of an example computer system P10 that may be used to implement the unit testing generation system 100 and the example methods described herein. For example, processor systems similar or identical to the example computer system P10 may be used to implement the example unit test generation system 100, the modules of FIG. 1, and the method of FIG. 5. Although the example computer system P10 is described below as including a plurality of peripherals, interfaces, chips, memories, etc., one or more of those elements may be omitted from other example processor systems used to implement the example unit test generation system 100.
As shown in FIG. 6, the computer system P10 includes a processor P12 that is coupled to an interconnection bus P14. The processor P12 includes a register set or register space P16, which is depicted in FIG. 6 as being entirely on-chip, but which could alternatively be located entirely or partially off-chip and directly coupled to the processor P12 via dedicated electrical connections and/or via the interconnection bus P14. The processor P12 may be any suitable processor, processing unit or microprocessor. Although not shown in FIG. 6, the system P10 may be a multi-processor system and, thus, may include one or more additional processors that are identical or similar to the processor P12 and that are communicatively coupled to the interconnection bus P14.
The processor P12 of FIG. 6 is coupled to a chipset P18, which includes a memory controller P20 and a peripheral input/output (I/O) controller P22. As is well known, a chipset typically provides I/O and memory management functions as well as a plurality of general purpose and/or special purpose registers, timers, etc. that are accessible or used by one or more processors coupled to the chipset P18. The memory controller P20 performs functions that enable the processor P12 (or processors if there are multiple processors) to access a system memory P24 and a mass storage memory P25.
The system memory P24 may include any desired type of volatile and/or non-volatile memory such as, for example, static random access memory (SRAM), dynamic random access memory (DRAM), flash memory, read-only memory (ROM), etc. The mass storage memory P25 may include any desired type of mass storage device. For example, if the example computer system P10 is used to implement the unit test generation system 100 (FIG. 1), the mass storage memory P25 may include a hard disk drive, an optical drive, a tape storage device, a solid-state memory (e.g., a flash memory, a RAM memory, etc.), a magnetic memory (e.g., a hard drive), or any other memory suitable for mass storage. As used herein, the terms “module” and “routine” refer to computer program logic used to provide the specified functionality. Thus, a module or a routine can be implemented in hardware, firmware, and/or software. In one embodiment, program modules and routines are stored in mass storage memory P25, loaded into system memory P24, and executed by a processor P12 or can be provided from computer program products that are stored in tangible computer-readable storage mediums (e.g. RAM, hard disk, optical/magnetic media, etc.).
The peripheral I/O controller P22 performs functions that enable the processor P12 to communicate with peripheral input/output (I/O) devices P26 and P28 and a network interface P30 via a peripheral I/O bus P32. The I/O devices P26 and P28 may be any desired type of I/O device such as, for example, a keyboard, a display (e.g., a liquid crystal display (LCD), a cathode ray tube (CRT) display, etc.), a navigation device (e.g., a mouse, a trackball, a capacitive touch pad, a joystick, etc.), etc. The network interface P30 may be, for example, an Ethernet device, an asynchronous transfer mode (ATM) device, an 802.11 device, a DSL modem, a cable modem, a cellular modem, etc. that enables the computer system P10 to communicate with another computer system.
While the memory controller P20 and the I/O controller P22 are depicted in FIG. 6 as separate functional blocks within the chipset P18, the functions performed by these blocks may be integrated within a single semiconductor circuit or may be implemented using two or more separate integrated circuits.
Throughout this specification, plural instances may implement components, operations, or structures described as a single instance. Although individual operations of one or more methods are illustrated and described as separate operations, one or more of the individual operations may be performed concurrently, and nothing requires that the operations be performed in the order illustrated. Structures and functionality presented as separate components in example configurations may be implemented as a combined structure or component. Similarly, structures and functionality presented as a single component may be implemented as separate components. These and other variations, modifications, additions, and improvements fall within the scope of the subject matter herein.
Certain embodiments are described herein as including logic or a number of components, modules, functions, or mechanisms. Modules may constitute either software modules (e.g., code embodied on a machine-readable medium or in a transmission signal) or hardware modules. A hardware module is tangible unit capable of performing certain operations and may be configured or arranged in a certain manner. In example embodiments, one or more computer systems (e.g., a standalone, client or server computer system) or one or more hardware modules of a computer system (e.g., a processor or a group of processors) may be configured by software (e.g., an application or application portion) as a hardware module that operates to perform certain operations as described herein.
In various embodiments, a hardware module may be implemented mechanically or electronically. For example, a hardware module may comprise dedicated circuitry or logic that is permanently configured (e.g., as a special-purpose processor, such as a field programmable gate array (FPGA) or an application-specific integrated circuit (ASIC)) to perform certain operations. A hardware module may also comprise programmable logic or circuitry (e.g., as encompassed within a general-purpose processor or other programmable processor) that is temporarily configured by software to perform certain operations. It will be appreciated that the decision to implement a hardware module mechanically, in dedicated and permanently configured circuitry, or in temporarily configured circuitry (e.g., configured by software) may be driven by cost and time considerations.
The various operations of example methods described herein may be performed, at least partially, by one or more processors that are temporarily configured (e.g., by software) or permanently configured to perform the relevant operations. Whether temporarily or permanently configured, such processors may constitute processor-implemented modules that operate to perform one or more operations or functions. The modules referred to herein may, in some example embodiments, comprise processor-implemented modules.
Similarly, the methods described herein may be at least partially processor-implemented. For example, at least some of the operations of a method may be performed by one or processors or processor-implemented hardware modules. The performance of certain of the operations may be distributed among the one or more processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the processor or processors may be located in a single location (e.g., within a home environment, an office environment or as a server farm), while in other embodiments the processors may be distributed across a number of locations.
The one or more processors may also operate to support performance of the relevant operations in a “cloud computing” environment or as a “software as a service” (SaaS). For example, at least some of the operations may be performed by a group of computers (as examples of machines including processors), these operations being accessible via a network (e.g., the Internet) and via one or more appropriate interfaces (e.g., application program interfaces (APIs).)
The performance of certain of the operations may be distributed among the one or more processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the one or more processors or processor-implemented modules may be located in a single geographic location (e.g., within a home environment, an office environment, or a server farm). In other example embodiments, the one or more processors or processor-implemented modules may be distributed across a number of geographic locations.
Some portions of this specification are presented in terms of algorithms or symbolic representations of operations on data stored as bits or binary digital signals within a machine memory (e.g., a computer memory). These algorithms or symbolic representations are examples of techniques used by those of ordinary skill in the data processing arts to convey the substance of their work to others skilled in the art. As used herein, an “algorithm” is a self-consistent sequence of operations or similar processing leading to a desired result. In this context, algorithms and operations involve physical manipulation of physical quantities. Typically, but not necessarily, such quantities may take the form of electrical, magnetic, or optical signals capable of being stored, accessed, transferred, combined, compared, or otherwise manipulated by a machine. It is convenient at times, principally for reasons of common usage, to refer to such signals using words such as “data,” “code,” “content,” “bits,” “values,” “elements,” “symbols,” “characters,” “terms,” “numbers,” “numerals,” or the like. These words, however, are merely convenient labels and are to be associated with appropriate physical quantities.
Unless specifically stated otherwise, discussions herein using words such as “processing,” “computing,” “calculating,” “determining,” “presenting,” “displaying,” or the like may refer to actions or processes of a machine (e.g., a computer) that manipulates or transforms data represented as physical (e.g., electronic, magnetic, or optical) quantities within one or more memories (e.g., volatile memory, non-volatile memory, or a combination thereof), registers, or other machine components that receive, store, transmit, or display information.
As used herein any reference to “some embodiments,” “one embodiment” or “an embodiment” means that a particular element, feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment. The appearances of the phrase “in one embodiment” or “in some embodiments” in various places in the specification are not necessarily all referring to the same embodiment.
Some embodiments may be described using the expression “coupled” and “connected” along with their derivatives. For example, some embodiments may be described using the term “coupled” to indicate that two or more elements are in direct physical or electrical contact. The term “coupled,” however, may also mean that two or more elements are not in direct contact with each other, but yet still co-operate or interact with each other. The embodiments are not limited in this context.
As used herein, the terms “comprises,” “comprising,” “includes,” “including,” “has,” “having” or any other variation thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, article, or apparatus that comprises a list of elements is not necessarily limited to only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Further, unless expressly stated to the contrary, “or” refers to an inclusive or and not to an exclusive or. For example, a condition A or B is satisfied by any one of the following: A is true (or present) and B is false (or not present), A is false (or not present) and B is true (or present), and both A and B are true (or present).
In addition, use of the “a” or “an” are employed to describe elements and components of the embodiments herein. This is done merely for convenience and to give a general sense of the invention. This description should be read to include one or at least one and the singular also includes the plural unless it is obvious that it is meant otherwise.
Upon reading this disclosure, those of skill in the art will appreciate still additional alternative structural and functional designs for a system and a process for generating a coverage report to indicate the success or failure of current unit tests and the amount of further testing that is required to fully test an application through the disclosed principles herein. Thus, while particular embodiments and applications have been illustrated and described, it is to be understood that the disclosed embodiments are not limited to the precise construction and components disclosed herein. Various modifications, changes and variations, which will be apparent to those skilled in the art, may be made in the arrangement, operation and details of the method and apparatus disclosed herein without departing from the spirit and scope defined in the appended claims.

## Claims

1. A computer-implemented method for generating unit test coverage report, comprising:
receiving a source code file including a plurality of source code units, wherein each source code unit of the plurality of source code units corresponds to one of a plurality of comments sections;
parsing the plurality of comments sections;
extracting to a first list, identification information for each source code unit from the corresponding comments section;
extracting a unit description for each source code unit from the corresponding comments section, wherein at least one unit description from the comments section includes an executable portion of code;
determining a function type corresponding to each unit description, wherein the function type is at least one of a function that establishes a value or a function that retrieves a value;
automatically generating a set of unit tests for each source code unit based on the unit description within the corresponding comments section and the determined function type, wherein the set of unit tests includes at least one unit test based on the determined function type and a unit test that includes the executable portion of code,
wherein generating the set of unit tests includes copying the unit description including the executable portion of code to a unit test stub corresponding to a source code unit type, and transforming each unit test stub into a corresponding one of a plurality of unit tests;
and executing the set of unit tests, wherein executing the unit test that includes the executable portion of code includes executing the executable portion of code;
generating a test result indication for each source code unit based on the execution of the set of unit tests, wherein the generated test result indication includes at least one of a pass result, fail result, and follow-up result;
storing the test result indication and the identification information for each source code unit in a list of tested source code units;
comparing the identification information for each source code unit in the first list to the list of tested source code units; and
based on the comparing, adding the identification information for each source code unit and the test result indication for each source code unit to the unit test coverage report.

2. The computer-implemented method of claim 1, wherein the unit test coverage report consisting of passed tested source code units indicates how many source code units within the tested source code units are covered by unit tests that pass.

3. The computer-implemented method of claim 1, wherein each member of the list of tested source code units corresponds to a unit test for each of the plurality of source code units.

4. A non-transitory computer-readable medium storing instructions, the instructions when executed by a processor generate a unit test coverage report by causing the processor to:
receive a source code file including a plurality of source code units, wherein each source code unit of the plurality of source code units corresponds to one of a plurality of comments sections;
parse the plurality of comments sections;
extract, to a first list, identification information for each source code unit from the corresponding comments section;
extract a unit description for each source code unit from the corresponding comments section, wherein at least one unit description from the comments section includes an executable portion of code;
determine a function type corresponding to each unit description, wherein the function type is at least one of a function that establishes a value or a function that retrieves a value;
automatically generate a set of unit tests for each source code unit based on the unit description within the corresponding comments section and the determined function type, wherein the set of unit tests includes at least one unit test based on the determined function type a unit test that includes the executable portion of code,
wherein generating a set of unit tests includes copying the unit description including the executable portion of code to a unit test stub corresponding to a source code unit, and transforming each unit test stub into a corresponding one of a plurality of unit tests;
execute the set of unit tests, wherein the executable portion of code is executed;
generate a test result indication for each source code unit based on the execution of the set of unit tests, wherein the generated test result indication includes at least one of a pass result, fail result, and follow-up result;
store the test result indication and the identification information for each source code unit in a list of tested source code units;
compare the identification information for each source code unit in the first list to the list of tested source code units; and
based on the comparison of the identification information for each source code unit in the first list to the list of tested source code units, add the identification information for each source code unit and the test result indication for each source code unit to the unit test coverage report.

5. The non-transitory computer-readable medium of claim 4, wherein the unit test coverage report indicates how many source code units within the tested source code units are covered by unit tests that pass.

6. The non-transitory computer-readable medium of claim 4, wherein each member of the list of tested source code units corresponds to a unit test for each of the plurality of source code units.

7. A computer system for generating a unit test coverage report, the system comprising:
a processor; and
memory, wherein the memory includes instructions that when executed by the processor are operable to:
store in a database a plurality of source code files, each source code file including a plurality of source code units, wherein each source code unit corresponds to one of a plurality of comments sections;
extract a unit description for each source code unit from the corresponding comments section, where at least one unit description from the comments section includes an executable portion of code;
determine a function type corresponding to each unit description, wherein the function type is at least one of a function that establishes a value or a function that retrieves a value;
automatically generate a set of unit tests for each source code unit based on the unit description within the corresponding comments section and the determined function type, wherein the set of unit tests includes at least one unit test based on the determined function type and a unit test that includes the executable portion of code,
wherein generating a set of unit tests includes copying the unit description including the executable portion of code to a unit test stub corresponding to a source code unit type, and transforming each unit test stub into a corresponding one of a plurality of unit tests;
execute the set of unit tests;
generate a test result indication for each source code unit based on the execution of the set of unit tests, wherein the generated test result indication includes at least one of a pass result, fail result, and follow-up result;
store the test result indication and identification information for each source code unit in a list of tested source code units;
read the plurality of comments sections;
parse the plurality of comments sections;
extract to a first list, the identification information of each source code unit from the corresponding comments section;
compare the identification information for each source code unit in the first list to the list of tested source code units indicating a test result of each source code unit;
and based on the comparison, add the test result indication to the unit test coverage report, wherein the unit test coverage report provides an indication as to how much of the source code file has been tested.

8. The computer system of claim 7, wherein the unit test coverage report consisting of passed tested source code units indicates how many source code units within the tested source code units are covered by unit tests that pass.

9. The computer system of claim 7, wherein each member of the list of tested source code units corresponds to a unit test for each of the plurality of source code units.

10. The non-transitory computer-readable medium of claim 4, wherein the unit test coverage report provides an indication as to how much of the source code unit testing has been completed.

11. The computer-implemented method of claim 1, further comprising:
including, in the unit test stub, instructions that generate an error when executed; and
determining whether the generated error matches a predetermined error response type.

12. The computer-implemented method of claim 1, wherein the executable portion of code within the unit description, if executed, would provide expected results from at least one of a function, method, class, and/or other unit of code from the source code file.