week5_Note
Project
Rules for submitting pull requests
Project Rules: What not to do when making pull request(PR)?
- Need to change the code to resolve conflicts so that developers can merge cleanly
- No communication with the user and developer. Only fixing the way you like.
- Do not choose documentation related issue.
- Do not adding too many commits to your PR. You PR should be short.
- Make minimal changes to current code. A PR that change less lines will be more likely to be accepted!
- Hit-and run PR: commits and run away without responding. This is very bad practice because:
- Waste time of developer in code review
- Developers need to correct you mistake because you didn;t even check if you are implementing the correct issue
- Developer mention you several times but do not respond. Leave a bad reputation in GitHub.
Recap: Failure and errors
- Why is the difference between failure and errors?
- 计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异(Discrepancy between a computed, observed or measured value or condition and the true, specified, or theoretically correct value or condition.),可译为“错误”。Error是能够导致系统出现Failure的系统内部状态。
- Failure:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to perform a function as required.)
Test Driven Development(TDD)
One of the core practices in XP
Kent Beck's rules
- Beck's concept of test-driven development centers on two basic rules.
- Eliminate duplication.
Ambiguity in Informal
If the maintenance contract number provided by the customer is not valid?
- Contract number cannot contain alphabets or special characters
- Contract number must be 5 digits
- Contract number cannot start with 0?
Steps in Test Driven Development (TDD)
- The iterative process
- Quickly add a test.
- Run all tests and see the new one fail.
- Make a little change to code.
- Run all tests and see them all succeed.
- Refactor to remove duplication
Which example has better tests?
- Each test should be independent of each other
- Any given behaviour should be specified in one and only
- Correct method signature should be assertEquals(expected,actual)
- Use .equals() to compare strings
Is there a standard measurement for test quality
Yes, code coverage!
What is Code Coverage
- Code 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 form of dynamic analysis)
- Code Coverage is classified as a White box testing
- White Box testing: Testing where internal structure/ design/ implementation of the item being tested is known
Benefits of Code Coverage
- Identify untested part of codebase
- Improve the quality by imporved test coverage
- Identify testing gaps or missing tests
- Identify the redundant/dead code
Coverage Criteria
To measure what percentage of code has been exercised by a test suite, one or more coverage
- Instructions Coverage
- Method’s bytecode stream is a sequence of instructions for JVM
- The Bytecode for a method are executed when that method is invoked.
- Statements Coverage
- Reports whether each executable statement was executed
- Branch Coverage
- Reports whether Boolean expressions evaluate to true
- Method Coverage
- Reports whether a method (function) was invoked while testing the application
- Class Coverage
- Report of number of classes from the code base covered.
Equation for Computing Coverage
\[\text{Statement Coverage} = \frac{\text{Number of executed statements}}{\text{Total number of statements}} \times 100\]
\[ \text{Branch Coverage} = \frac{\text{Number of Executed Branches}}{\text{Total number of Branches}} \times 100 \]
Code Coverage Analysis Process
- Writing test cases and execute them
- Finding areas of code not covered using Code Coverage Tool
- Creating additional tests for identified gaps to increase test coverage
- Determining a quantitative measure of code coverage
Code Coverage using JaCoCo
- JaCoCo is an open source code coverage Tool for Java, which has been created by the EclEmma team
- Configure JaCoCo agent with JVM of your system to instrument java classes
- .EXEC file gets generated while the test cases are executed on the sys
- Generate Code Coverage report using ant (in different format)
Mutation Testing
General View
We are performing muttion analysis whenever we
- use well defined rules(mutation operators)
- defined on syntactic description(grammars)
- to make systematic changes(Applied universally or according to empirically verified distribution)
- to the syntax or to objects developed from the syntax
Why Mutation?
- Mutant processes are created to try to mimic typical syntactic errors made by program
- Many differing mutants are run against the specified tests to assess the quality of the tests
- The tests are attributed a score between 0 and 1, as to whether they can distinguish between the original and the mutants.
Mutators
Mutators are patterns applied to source code to produce mutations