Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarC# fails when parsing xUnit test results with empty <assembly> tags #406

Closed
hesantan opened this issue Jun 7, 2017 · 0 comments
Closed
Assignees
Labels
Area: SQ Plugin Java plugin related issues. Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@hesantan
Copy link

hesantan commented Jun 7, 2017

Description

We are using the Jenkins SonarQube Scanner for MSBuild with xUnit and OpenCover. When we are running the scanner on all our projects and one of the projects is still under the developer with no added tests or tests are not marked correctly, the analysis fails to complete. There is an exception being thrown because xUnit creates empty <assembly> tags for assemblies found with no tests.

Repro steps

  1. Create an a project that uses xUnit and has no tests
  2. Build the assembly
  3. Run xUnit console runner against the built assembly as shown in Unit Test Execution Results Import (C#, VB.NET)
  4. The scanner will fail after MSBuild.SonarQube.Runner.exe end

Expected behavior

Empty elements should be ignored.

Actual behavior

Exception is thrown and analysis is incomplete

org.sonar.plugins.dotnet.tests.ParseErrorException: Missing attribute "total" in element <assembly> in C:\Temp\TN-alpha_it\xunit-results.xml at line 103

Jenkins Console:

00:08:59.427 INFO: Sensor Sonar-Sonargraph-Plugin [3.5] [Sonargraph] (done) | time=0ms
00:08:59.427 INFO: Sensor Embedded CSS Analyzer Sensor [css]
00:08:59.427 INFO: 0 source files to be analyzed
00:08:59.427 INFO: Sensor Embedded CSS Analyzer Sensor [css] (done) | time=0ms
00:08:59.427 INFO: Sensor C# Unit Tests Coverage Report Import [csharp]
00:08:59.427 INFO: 0/0 source files have been analyzed
00:08:59.427 INFO: Parsing the OpenCover report C:\Temp\TN-alpha_it\opencover-results.xml
00:09:00.036 INFO: Adding this code coverage report to the cache for later reuse: C:\Temp\TN-alpha_it\opencover-results.xml
00:09:00.052 INFO: Sensor C# Unit Tests Coverage Report Import [csharp] (done) | time=625ms
00:09:00.052 INFO: Sensor C# Integration Tests Coverage Report Import [csharp]
00:09:00.052 INFO: Sensor C# Integration Tests Coverage Report Import [csharp] (done) | time=0ms
00:09:00.052 INFO: Sensor C# Unit Test Results Import [csharp]
00:09:00.052 INFO: Parsing the XUnit Test Results file C:\Temp\TN-alpha_it\xunit-results.xml
00:09:00.567 INFO: ------------------------------------------------------------------------
00:09:00.567 INFO: EXECUTION FAILURE
00:09:00.567 INFO: ------------------------------------------------------------------------
00:09:00.567 INFO: Total time: 1:16.154s
00:09:00.692 INFO: Final Memory: 58M/696M
00:09:00.692 INFO: ------------------------------------------------------------------------
00:09:00.692 ERROR: Error during SonarQube Scanner execution
00:09:00.692 org.sonar.plugins.dotnet.tests.ParseErrorException: Missing attribute "total" in element <assembly> in C:\Temp\TN-alpha_it\xunit-results.xml at line 103
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XmlParserHelper.parseError(XmlParserHelper.java:150)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XmlParserHelper.getRequiredAttribute(XmlParserHelper.java:132)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XmlParserHelper.getRequiredIntAttribute(XmlParserHelper.java:97)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XUnitTestResultsFileParser$Parser.handleAssemblyTag(XUnitTestResultsFileParser.java:67)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XUnitTestResultsFileParser$Parser.parse(XUnitTestResultsFileParser.java:58)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XUnitTestResultsFileParser.accept(XUnitTestResultsFileParser.java:35)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.XUnitTestResultsFileParser.accept(XUnitTestResultsFileParser.java:28)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.UnitTestResultsAggregator.aggregate(UnitTestResultsAggregator.java:89)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.UnitTestResultsAggregator.aggregate(UnitTestResultsAggregator.java:80)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.UnitTestResultsImportSensor.analyze(UnitTestResultsImportSensor.java:67)
00:09:00.692 	at org.sonar.plugins.dotnet.tests.UnitTestResultsImportSensor.execute(UnitTestResultsImportSensor.java:61)
00:09:00.692 	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
00:09:00.692 	at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
00:09:00.692 	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
00:09:00.692 	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
00:09:00.692 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:175)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
00:09:00.692 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:262)
00:09:00.692 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:257)
00:09:00.692 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:247)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
00:09:00.692 	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
00:09:00.692 	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
00:09:00.692 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
00:09:00.692 	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
00:09:00.692 	at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
00:09:00.692 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
00:09:00.692 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
00:09:00.692 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
00:09:00.692 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
00:09:00.692 	at java.lang.reflect.Method.invoke(Method.java:498)
00:09:00.692 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
00:09:00.692 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
00:09:00.692 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
00:09:00.692 	at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
00:09:00.692 	at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
00:09:00.692 	at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
00:09:00.692 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
00:09:00.692 ERROR: 
00:09:00.692 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
00:09:00.848 The SonarQube Scanner did not complete successfully
00:09:00.848 11:09:46.972  Creating a summary markdown file...
00:09:00.848 11:09:46.972  Post-processing failed. Exit code: 1
00:09:00.958 ERROR: Execution of SonarQube Scanner for MSBuild failed (exit code 1)

Known workarounds

Add filters to to prevent the assembly from being scanned by xUnit.

Related information

  • SonarC# Version
    5.11 (build 1761) installed

  • Visual Studio Version
    Visual Studio 2015/ Visual Studio 2017

  • If running through the Scanner for MSBuild, its version
    SonarQube Scanner for MSBuild 2.3.2

@valhristov valhristov added Area: SQ Plugin Java plugin related issues. Type: Bug Exceptions and blocking issues during analysis. labels Jun 8, 2017
@valhristov valhristov added this to the near-future milestone Jun 8, 2017
@Evangelink Evangelink self-assigned this Jun 19, 2017
@Evangelink Evangelink modified the milestones: 6.1, near-future Jun 19, 2017
@Evangelink Evangelink changed the title SonarQube Scanner for MSBuild fails to parse xUnit results with empty <assembly> tags SonarC# fails when parsing xUnit test results with empty <assembly> tags Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: SQ Plugin Java plugin related issues. Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

3 participants