utility of test coverage metrics in tdd

10
Utility of Test Coverage Metrics in TDD Virender Kumar TDD Trainer, Consultant [email protected]

Upload: xp-conference-india

Post on 20-Jan-2017

311 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Utility of Test Coverage Metrics in TDD

Utility of Test Coverage Metrics in TDD

Virender KumarTDD Trainer, [email protected]

Page 2: Utility of Test Coverage Metrics in TDD

Learning Objectives

• TDD Overview• Common Test Coverage Metrics• Significance of Test Coverage Metrics in TDD• Test Coverage Measurement Tools

Page 3: Utility of Test Coverage Metrics in TDD

TDD

• Software development technique in which tests are written prior to code

• If you can’t write test for what you are trying to code, then you should not be thinking about coding

• TDD reduces the gap between design and feedback (performance achieved by implementing the design)

Page 4: Utility of Test Coverage Metrics in TDD

Test Coverage Metrics

• Statement Coverage• Branch Coverage• Condition Coverage• MCDC• Data Flow Coverage• Path Coverage• Mutation Coverage

Page 5: Utility of Test Coverage Metrics in TDD

Mutation Coverage

• Mutation – small change in program• Apply mutations to program to obtain set of

mutants M1, M2 … Mn• Run test suite on each of mutants. Mutant is

killed if an error is detected• Mutation Test Coverage = No. of mutants killed /

Total no. of mutants• Has to be automated for any reasonable sized

program

Page 6: Utility of Test Coverage Metrics in TDD

Mutation Coverage

• May not be practical to consider all possible mutants

• Use mutation operators (rules) to generate mutants

• Value mutations – change values to reflect errors in reasoning about programs

• Decision mutations – change relational operators or parenthesisation in conditions

• Statement mutations – change whole line of code

Page 7: Utility of Test Coverage Metrics in TDD

Test Coverage Measurement Tools

• PIT (www.pitest.org)• Jumble (http://jumble.sourceforge.net/)• Clover

(https://www.atlassian.com/software/clover/overview)

• Cobertura (http://cobertura.github.io/cobertura/)

• EMMA (http://emma.sourceforge.net/)

Page 8: Utility of Test Coverage Metrics in TDD

PIT

• Measures line coverage and mutation coverage• Bytecode based mutant generation• Test selection is automatic – based on line

coverage• Can be integrated with Ant or Maven based

build systems• Compatible with most mocking frameworks,

except Powermock and Jmockit

Page 9: Utility of Test Coverage Metrics in TDD

Observations

• TDD does not imply that the tests are perfect• Test Coverage measurements are relevant to

TDD• Mutation coverage tells whether something is

really tested• Tools are available which make it practical to

measure mutation coverage

Page 10: Utility of Test Coverage Metrics in TDD

Future Work

• Collect more data on test coverage in TDD• Effectiveness of mutation coverage vs. other

coverage metrics• Comparison between various coverage

measurement tools• Study effect of mocking frameworks on code

coverage