Repository navigation
Description
Part of #233.
Problem
The codegen modules extracted in #368 are meant to be reusable by other code generators. Today they are tested almost only through the tests of simple-builder (processor); their own tests cover little or nothing.
| Module | Own tests | Line coverage from own tests | Line coverage including the simple-builder tests |
|---|---|---|---|
codegen-core |
18 | 0% | 96% |
simple-processor |
1 | 0% | 92% |
codegen-roaster |
32 | 31% | 92% |
codegen-testing |
0 | no report | not measured |
core |
87 | 81% | – |
processor (simple-builder) |
485 | 98% | – |
Measured on main with mvn clean install -Pmetrics: the JaCoCo report of each module against the aggregate report of processor. The 18 tests of codegen-core cover only model classes, which are excluded from coverage.
The gap is not visible in SonarCloud and Codecov, because both read the aggregate report, where the generic modules count as covered by the simple-builder tests.
Goal
codegen-core, simple-processor, codegen-roaster and codegen-testing each prove their behavior with tests in their own module, without simple-builder types, and their coverage is measured from these tests alone.
Tasks
-
Move the tests that already test a generic class. These tests sit in
processorbut do not need the builder domain:Test (in processor)Tests Belongs to JavaLangAnalyserTest22 simple-processorOptionValueParsersTest7 simple-processorProcessorOptionRegistryTest2 simple-processorCodegenProcessorConfigurationTest1 simple-processorElementCollectorTest1 simple-processorActivePerformanceTrackerTest25 codegen-coreFormatterProfileTestUtilsTest2 codegen-testing -
Write the missing tests.
simple-processor:AbstractCodegenProcessor,JavaLangMapperandFieldAnnotationExtractor, driven by a minimal test processor (as inMinimalCodegenProcessorTest) instead ofBuilderProcessor.codegen-roaster:RoasterCodeGeneratoris tested only fromprocessor(RoasterCodeGeneratorEdgeCasesTestthrough generated builders,RoasterCodeGeneratorResilienceTestwith generic DTOs, see the next task). It needs tests in its own module that pass generic DTOs to it directly.codegen-core:logging,utilandenums.codegen-testing: the helper classes themselves.
-
Move
RoasterCodeGeneratorResilienceTesttocodegen-roasterand drop the direct dependency. It is the only class inprocessorthat usescodegen-roastertypes (RoasterCodeGenerator,RoasterSourceFormatter,RoasterMapperException); the main code names the module in one javadoc only. The test already passes generic DTOs to the generator, but builds its environment fromBuilderProcessingContext,AnnotationProcessingEnvironmentandMessagerProcessingLogger. Incodegen-roasterit needs aGenerationEnvironmentbuilt fromcodegen-coreandcodegen-testingtypes, becausecodegen-roastercannot depend onsimple-processor. After the move, remove thecodegen-roasterdependency fromprocessor/pom.xml: it then arrives transitively throughsimple-processor, as Checking dependencies after separation - Roaster should become a transitive dependency #374 asks for Roaster itself (follow-up of build: depend on Roaster only in codegen-roaster (#374) #394). -
Measure each module on its own. The coverage of a generic module comes from its own report, not from the aggregate of
processor. -
Agree on the target per module. Codecov requires 80% for the project and 90% for new code today.
Rules for the tests
codegen-corecannot usecodegen-testing(dependency cycle), so its tests use plain JUnit.- Use the existing assertion helpers:
ProcessorAsserts(codegen-testing) for generic tests,BuilderAssertsfor simple-builder tests. - Check generated code with text blocks instead of single lines or small fragments. This finds real problems and keeps the expectation readable.
Activity
[-]Each module should have good test coverage from its own tests[/-][+]Each module should be covered by its own tests[/+]test: lift per-module coverage and share test helpers (java-helpers#390)
test: split processor tests into the modules they cover (#401)