词条 | Code coverage |
释义 |
In computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high test coverage, measured as a percentage, has had more of its source code executed during testing, which suggests it has a lower chance of containing undetected software bugs compared to a program with low test coverage.[1][2] Many different metrics can be used to calculate test coverage; some of the most basic are the percentage of program subroutines and the percentage of program statements called during execution of the test suite. Test coverage was among the first methods invented for systematic software testing. The first published reference was by Miller and Maloney in Communications of the ACM in 1963.[3] Coverage criteriaTo measure what percentage of code has been exercised by a test suite, one or more coverage criteria are used. Coverage criteria are usually defined as rules or requirements, which a test suite needs to satisfy.[4] Basic coverage criteriaThere are a number of coverage criteria, the main ones being:[5]
For example, consider the following C function: Assume this function is a part of some bigger program and this program was run with some test suite.
Condition coverage does not necessarily imply branch coverage. For example, consider the following fragment of code: Condition coverage can be satisfied by two tests:
However, this set of tests does not satisfy branch coverage since neither case will meet the Fault injection may be necessary to ensure that all conditions and branches of exception handling code have adequate coverage during testing. Modified condition/decision coverage{{Main article|Modified Condition/Decision Coverage}}A combination of function coverage and branch coverage is sometimes also called decision coverage. This criterion requires that every point of entry and exit in the program has been invoked at least once, and every decision in the program has taken on all possible outcomes at least once. In this context the decision is a boolean expression composed of conditions and zero or more boolean operators. This definition is not the same as branch coverage,[6] however, some do use the term decision coverage as a synonym for branch coverage.[7]Condition/decision coverage requires that both decision and condition coverage be satisfied. However, for safety-critical applications (e.g., for avionics software) it is often required that modified condition/decision coverage (MC/DC) be satisfied. This criterion extends condition/decision criteria with requirements that each condition should affect the decision outcome independently. For example, consider the following code: The condition/decision criteria will be satisfied by the following set of tests:
However, the above tests set will not satisfy modified condition/decision coverage, since in the first test, the value of 'b' and in the second test the value of 'c' would not influence the output. So, the following test set is needed to satisfy MC/DC:
Multiple condition coverageThis criterion requires that all combinations of conditions inside each decision are tested. For example, the code fragment from the previous section will require eight tests:
Parameter value coverageParameter value coverage (PVC) requires that in a method taking parameters, all the common values for such parameters be considered. The idea is that all common possible values for a parameter are tested.[8] For example, common values for a string are: 1) null, 2) empty, 3) whitespace (space, tabs, newline), 4) valid string, 5) invalid string, 6) single-byte string, 7) double-byte string. It may also be appropriate to use very long strings. Failure to test each possible parameter value may leave a bug. Testing only one of these could result in 100% code coverage as each line is covered, but as only one of seven options are tested, there is only 14.2% PVC. Other coverage criteriaThere are further coverage criteria, which are used less often:
Safety-critical or dependable applications are often required to demonstrate 100% of some form of test coverage. For example, the ECSS-E-ST-40C standard demands 100% statement and decision coverage for two out of four different criticality levels; for the other ones, target coverage values are up to negotiation between supplier and customer.[11] However, setting specific target values - and, in particular, 100% - has been criticized by practitioners for various reasons (cf.[12]) Martin Fowler writes: "I would be suspicious of anything like 100% - it would smell of someone writing tests to make the coverage numbers happy, but not thinking about what they are doing".[13] Some of the coverage criteria above are connected. For instance, path coverage implies decision, statement and entry/exit coverage. Decision coverage implies statement coverage, because every statement is part of a branch. Full path coverage, of the type described above, is usually impractical or impossible. Any module with a succession of decisions in it can have up to paths within it; loop constructs can result in an infinite number of paths. Many paths may also be infeasible, in that there is no input to the program under test that can cause that particular path to be executed. However, a general-purpose algorithm for identifying infeasible paths has been proven to be impossible (such an algorithm could be used to solve the halting problem).[14] Basis path testing is for instance a method of achieving complete branch coverage without achieving complete path coverage.[15] Methods for practical path coverage testing instead attempt to identify classes of code paths that differ only in the number of loop executions, and to achieve "basis path" coverage the tester must cover all the path classes.{{citation needed|date=July 2014}}{{clarify|date=July 2014}} {{refimprove section|date=February 2015}}In practiceThe target software is built with special options or libraries and run under a controlled environment, to map every executed function to the function points in the source code. This allows testing parts of the target software that are rarely or never accessed under normal conditions, and helps reassure that the most important conditions (function points) have been tested. The resulting output is then analyzed to see what areas of code have not been exercised and the tests are updated to include these areas as necessary. Combined with other test coverage methods, the aim is to develop a rigorous, yet manageable, set of regression tests. In implementing test coverage policies within a software development environment, one must consider the following:
Software authors can look at test coverage results to devise additional tests and input or configuration sets to increase the coverage over vital functions. Two common forms of test coverage are statement (or line) coverage and branch (or edge) coverage. Line coverage reports on the execution footprint of testing in terms of which lines of code were executed to complete the test. Edge coverage reports which branches or code decision points were executed to complete the test. They both report a coverage metric, measured as a percentage. The meaning of this depends on what form(s) of coverage have been used, as 67% branch coverage is more comprehensive than 67% statement coverage. Generally, test coverage tools incur computation and logging in addition to the actual program thereby slowing down the application, so typically this analysis is not done in production. As one might expect, there are classes of software that cannot be feasibly subjected to these coverage tests, though a degree of coverage mapping can be approximated through analysis rather than direct testing. There are also some sorts of defects which are affected by such tools. In particular, some race conditions or similar real time sensitive operations can be masked when run under test environments; though conversely, some of these defects may become easier to find as a result of the additional overhead of the testing code. Usage in industryTest coverage is one consideration in the safety certification of avionics equipment. The guidelines by which avionics gear is certified by the Federal Aviation Administration (FAA) is documented in DO-178B[16] and DO-178C.[17] Test coverage is also a requirement in part 6 of the automotive safety standard ISO 26262 Road Vehicles - Functional Safety.[18] See also{{portal|Software Testing}}
References1. ^{{cite book|last1=Brader|first1=Larry|last2=Hilliker|first2=Howie|last3=Wills|first3=Alan|title=Testing for Continuous Delivery with Visual Studio 2012|date=March 2, 2013|publisher=Microsoft|isbn=1621140180|page=30|url=https://msdn.microsoft.com/en-us/library/jj159344.aspx|accessdate=16 June 2016|chapter=Chapter 2 Unit Testing: Testing the Inside}} {{DEFAULTSORT:Code Coverage}}2. ^{{cite web|last1=Williams|first1=Laurie|last2=Smith|first2=Ben|last3=Heckman|first3=Sarah|title=Test Coverage with EclEmma|url=http://realsearchgroup.org/SEMaterials/tutorials/eclemma|website=Open Seminar Software Engineering|publisher=North Carolina State University|accessdate=16 June 2016}} 3. ^{{cite journal | author = Joan C. Miller, Clifford J. Maloney | title = Systematic mistake analysis of digital computer programs | journal = Communications of the ACM | volume = 6 | issue = 2 |date=February 1963 | publisher = ACM | location = New York, NY, USA | issn = 0001-0782 | pages = 58–63 | doi = 10.1145/366246.366248}} 4. ^{{cite book | author=Paul Ammann, Jeff Offutt | title=Introduction to Software Testing |publisher=Cambridge University Press| year=2013}} 5. ^{{cite book | author=Glenford J. Myers | title=The Art of Software Testing, 2nd edition |publisher=Wiley | year=2004| isbn=0-471-46912-2}} 6. ^Position Paper CAST-10 (June 2002). What is a "Decision" in Application of Modified Condition/Decision Coverage (MC/DC) and Decision Coverage (DC)? 7. ^MathWorks. Types of Model Coverage. 8. ^Unit Testing with Parameter Value Coverage (PVC) 9. ^M. R. Woodward, M. A. Hennell, "On the relationship between two control-flow coverage criteria: all JJ-paths and MCDC", Information and Software Technology 48 (2006) pp. 433-440 10. ^Ting Su, Ke Wu, Weikai Miao, Geguang Pu, Jifeng He, Yuting Chen, and Zhendong Su. "A Survey on Data-Flow Testing". ACM Comput. Surv. 50, 1, Article 5 (March 2017), 35 pages. 11. ^ECSS-E-ST-40C: Space engineering - Software. ECSS Secretariat, ESA-ESTEC. March, 2009 12. ^C. Prause, J. Werner, K. Hornig, S. Bosecker, M. Kuhrmann (2017): [https://www.researchgate.net/profile/Marco_Kuhrmann/publication/319141355_Is_100_Test_Coverage_a_Reasonable_Requirement_Lessons_Learned_from_a_Space_Software_Project/links/599467faaca272ec9087f82a/Is-100-Test-Coverage-a-Reasonable-Requirement-Lessons-Learned-from-a-Space-Software-Project.pdf Is 100% Test Coverage a Reasonable Requirement? Lessons Learned from a Space Software Project]. In: PROFES 2017. Springer. Last accessed: 2017-11-17 13. ^Martin Fowler's blog: [https://martinfowler.com/bliki/TestCoverage.html TestCoverage.] Last accessed: 2017-11-17 14. ^Dorf, Richard C.: Computers, Software Engineering, and Digital Devices, Chapter 12, pg. 15. CRC Press, 2006. {{ISBN|0-8493-7340-9}}, {{ISBN|978-0-8493-7340-4}}; via [https://books.google.com/books?id=jykvlTCoksMC&pg=PT386&lpg=PT386&dq=%22infeasible+path%22+%22halting+problem%22&source=web&ots=WUWz3qMPRv&sig=dSAjrLHBSZJcKWZfGa_IxYlfSNA&hl=en&sa=X&oi=book_result&resnum=1&ct=result Google Book Search] 15. ^{{cite book|author1=Y.N. Srikant|author2=Priti Shankar|title=The Compiler Design Handbook: Optimizations and Machine Code Generation|year=2002|publisher=CRC Press|isbn=978-1-4200-4057-9|page=249}} 16. ^1 RTCA/DO-178B, Software Considerations in Airborne Systems and Equipment Certification, Radio Technical Commission for Aeronautics, December 1, 1992 17. ^RTCA/DO-178C, Software Considerations in Airborne Systems and Equipment Certification, Radio Technical Commission for Aeronautics, January, 2012. 18. ^{{cite book | title =ISO 26262-6:2011(en) Road vehicles -- Functional safety -- Part 6: Product development at the software level | publisher =International Standardization Organization | url =http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=51362}} 3 : Software testing|Software metrics|Software testing tools |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。