Use the TDD (Test-Driven Development) methodology to implement a rule in an efficient and structured way.
- Define test resources for the rule to be implemented with all possible cases:
- Compliant code
- Non-compliant code
- Code with elements that should not be analyzed
- Location of test resource files in a common place for all unit tests and integration tests :
- main directory : "src/it/test-projects"
- on subdirecroy for each rule ("GCI" pattern)
- Create the rule implementation class in the package "org.greencodeinitiative.creedengo.python.checks"
- Add the "Rule" annotation with the correct rule id (the rule is previously defined in another maven component named "creedengo-rules-specifications")
- Extend the "PythonSubscriptionCheck" class
- Implement the "initialize" method which will be used to declare the AST node types to analyze in depth but leave it empty for now
- Create the rule unit test class in the package "org.greencodeinitiative.creedengo.python.checks"
- Verify that unit tests fail with non-compliant test resources
- Implement the rule in the implementation class created in step 1
- Implement the "initialize" method to declare the AST node types to analyze in depth
- Implement private methods to analyze in depth the declared AST nodes and raise issues if needed
- Verify that unit tests pass with both compliant and non-compliant test resources
- Add a test method in the integration class "GCIRulesIT" for the implemented rule using the same pattern as other existing test methods
- Verify that integration tests pass with both compliant and non-compliant test resources