Add more complexity to the test case
The next step in the KAST checker development process is to add more tests to the test case. Tests to add can be:
- false positive tests - ensure that the checker does not generate errors for certain conditions
- more complex tests - ensure that the checker will generate an error for special or more complex cases
For the sample checker in this tutorial, three more false-positive test cases will be added. The checks that will be added are:
- assignment operation without following '+' or '-'
- assignment followed by unary minus expression
- normal '+=' operation
These cases should not generate a Klocwork issue report.
Change the code in Testcase.java
to:
class Testcase { public void method() { int x = 2; // OK - assignment only int j = x =+ 5; // Error: assignment instead of '+=' int k = x =- 100; // OK - unary '-' instead of unary '+' x += 12; // OK - normal '+=' operation, no typo } }
Run the test again using Checker Studio. See Test the KAST expression.
The results indicate that no false positives were generated (all the test cases were covered).