Skip to content

Commit

Permalink
feat(Tests): support for multiple test reports (#191)
Browse files Browse the repository at this point in the history
Co-authored-by: Gilles Grousset <[email protected]>
  • Loading branch information
zippy1978 and Gilles Grousset authored Aug 18, 2023
1 parent dea7fa9 commit 5822ff6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ You may follow and upvote these related issue if interested:

All options are configurable in the SonarQube UI, via `sonar-project.properties` or `-D` parameters.

| Name | Options | Default | Description |
|----------------------------------------|--------------------------------------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `sonar.dart.analyzer.mode` | <code>DETECT&#124;DART&#124;FLUTTER&#124;MANUAL&#124;DARTANALYZER</code> | `DETECT` | By default the plugin attempts to detect a fitting analyzer (`flutter analyze` or `dart analyze`) by parsing the `environment` from `pubspec.yaml`. This can be set to `MANUAL` to provide and existing report file. For compatibility with older Dart versions, this can be set to `DARTANALYZER`. |
| `sonar.dart.analyzer.options.override` | <code>true&#124;false</code> | `true` | By default any local `analysis_options.yaml` will be replaced for the analysis. This can be prevented by setting this to `false`. |
| `sonar.dart.analyzer.report.mode` | <code>DETECT&#124;MACHINE&#124;LEGACY</code> | `DETECT` | The new machine readable output can be automatically detected if Dart SDK is available on the $PATH. |
| `sonar.dart.analyzer.report.path` | A file path | - | This is required if the analyzer mode is set to `MANUAL`. |
| `sonar.flutter.tests.reportPath` | A file path | - | The path to the test report JSON file. |
| `sonar.flutter.coverage.reportPath` | A file path | - | The path to the test coverage file in LCOV format. |
| Name | Options | Default | Description |
|----------------------------------------|--------------------------------------------------------------------------|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `sonar.dart.analyzer.mode` | <code>DETECT&#124;DART&#124;FLUTTER&#124;MANUAL&#124;DARTANALYZER</code> | `DETECT` | By default the plugin attempts to detect a fitting analyzer (`flutter analyze` or `dart analyze`) by parsing the `environment` from `pubspec.yaml`. This can be set to `MANUAL` to provide and existing report file. For compatibility with older Dart versions, this can be set to `DARTANALYZER`. |
| `sonar.dart.analyzer.options.override` | <code>true&#124;false</code> | `true` | By default any local `analysis_options.yaml` will be replaced for the analysis. This can be prevented by setting this to `false`. |
| `sonar.dart.analyzer.report.mode` | <code>DETECT&#124;MACHINE&#124;LEGACY</code> | `DETECT` | The new machine readable output can be automatically detected if Dart SDK is available on the $PATH. |
| `sonar.dart.analyzer.report.path` | A file path | - | This is required if the analyzer mode is set to `MANUAL`. |
| `sonar.flutter.tests.reportPath` | Comma separated list of file paths (wildcard not supported) | `tests.output` | The path to the test report JSON file. |
| `sonar.flutter.coverage.reportPath` | A file path | `coverage/lcov.info` | The path to the test coverage file in LCOV format. |


## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ public void describe(SensorDescriptor sensorDescriptor) {

@Override
public void execute(SensorContext sensorContext) {
File reportFile = sensorContext.fileSystem().resolvePath(reportPath(sensorContext));

FlutterTestReportParser parser = new FlutterTestReportParser();
try {
List<FlutterUnitTestSuite> suites = parser.parse(reportFile);
suites.forEach(s -> saveSuite(s, sensorContext));
} catch (IOException e) {
throw new IllegalStateException("Failed to parse test report", e);
for (String reportPath : reportPaths(sensorContext)) {
File reportFile = new File(reportPath);
LOGGER.debug("Parsing test report: {}", reportPath);
try {
List<FlutterUnitTestSuite> suites = parser.parse(reportFile);
suites.forEach(s -> saveSuite(s, sensorContext));
} catch (IOException e) {
throw new IllegalStateException("Failed to parse test report", e);
}

}

}

private String reportPath(SensorContext sensorContext) {
private String[] reportPaths(SensorContext sensorContext) {
return sensorContext.config()
.get(REPORT_PATH_KEY)
.orElse(DEFAULT_REPORT_PATH);
.orElse(DEFAULT_REPORT_PATH).split(",");
}

private void saveSuite(FlutterUnitTestSuite suite, SensorContext sensorContext) {
Expand All @@ -72,7 +77,7 @@ private void saveSuite(FlutterUnitTestSuite suite, SensorContext sensorContext)
return;
}

LOGGER.debug("Parsing tests from {}", suite.getPath());
LOGGER.debug("Parsing tests from {}, ({} test(s))", suite.getPath(), suite.getCount());

saveMeasure(sensorContext, inputFile, CoreMetrics.SKIPPED_TESTS, (int) suite.getSkippedCount());
saveMeasure(sensorContext, inputFile, CoreMetrics.TESTS, (int) (suite.getCount()));
Expand Down

0 comments on commit 5822ff6

Please sign in to comment.