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

java.lang.UnsupportedOperationException in junit test reporting #26

Closed
mariusstaicu opened this issue Sep 1, 2017 · 7 comments
Closed

Comments

@mariusstaicu
Copy link
Contributor

Problem with junit test reporting

I have the following error when runnig sonar-runner

java.lang.UnsupportedOperationException: Can not add the same measure twice on [moduleKey=<obscured>:fix-missing-golint-issues1123, relative=gsm/sms_pusher_test.go, basedir=<obscured>]: DefaultMeasure[component=[moduleKey=<obscured>:fix-missing-golint-issues1123, relative=gsm/sms_pusher_test.go, basedir=<obscured>],metric=Metric[id=<null>,key=skipped_tests,description=Number of skipped unit tests,type=INT,direction=-1,domain=Coverage,name=Skipped Unit Tests,qualitative=true,userManaged=false,enabled=true,worstValue=<null>,bestValue=0.0,optimizedBestValue=true,hidden=false,deleteHistoricalData=false,decimalScale=<null>],value=0,fromCore=false]

Steps to Reproduce

I have a test.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
	<testsuite tests="6" failures="0" time="1.010" name="<obscured>/api">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="api" name="TestEnableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestCannotEnableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestDisableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestCannotDisableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestSendSms" time="0.000"></testcase>
		<testcase classname="api" name="TestCantSendSms" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="2" failures="0" time="0.004" name="<obscured>/cpuinfo">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="cpuinfo" name="TestReadCPUInfo" time="0.000"></testcase>
		<testcase classname="cpuinfo" name="TestUniqueSerialID" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="7" failures="0" time="0.010" name="<obscured>/gsm">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="gsm" name="TestRunCommand" time="0.000"></testcase>
		<testcase classname="gsm" name="TestHelperProcess" time="0.000"></testcase>
		<testcase classname="gsm" name="TestActivate" time="0.000"></testcase>
		<testcase classname="gsm" name="TestDisable" time="0.000"></testcase>
		<testcase classname="gsm" name="TestDisableSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestSendSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestCannotCreateSmsPusher" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="13" failures="0" time="0.006" name="<obscured>/protocol">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="protocol" name="TestGetBitForEmptyString" time="0.000"></testcase>
		<testcase classname="protocol" name="TestGetBitForNotEmptyString" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionLowerThanNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionEqualWithNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionGreaterThanNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeMessagePayloadTooLong" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecode" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodeRawValue" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodePowerUnitData" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodePairingRequest" time="0.000"></testcase>
		<testcase classname="protocol" name="TestDecodeNoPayload" time="0.000"></testcase>
		<testcase classname="protocol" name="TestAckPayloadNotImplemented" time="0.000"></testcase>
		<testcase classname="protocol" name="TestDefaultPayloadReturnsException" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="6" failures="0" time="23.682" name="<obscured>/radio">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="radio" name="TestInitRadio" time="0.000"></testcase>
		<testcase classname="radio" name="TestStartStop" time="0.020"></testcase>
		<testcase classname="radio" name="TestSetPairingMode" time="0.000"></testcase>
		<testcase classname="radio" name="TestReceiveRawData" time="0.510"></testcase>
		<testcase classname="radio" name="TestAwaitPairingRequestTimeout" time="21.500"></testcase>
		<testcase classname="radio" name="TestPairingSuccessful" time="1.650"></testcase>
	</testsuite>
	<testsuite tests="6" failures="0" time="0.003" name="<obscured>/repository">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="repository" name="TestStoreSensor" time="0.000"></testcase>
		<testcase classname="repository" name="TestStoreField" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorByID" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetAll" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorIDForExistentSensor" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorIDForNewSensor" time="0.000"></testcase>
	</testsuite>
</testsuites>

Content of your sonar-project.properties

no sonar-project.properties, passing url, login, project, version, sources, branch as cmd line arguments to sonnar-scanner

Log of sonar-scanner related to the plugin

ERROR: Error during SonarQube Scanner execution
java.lang.UnsupportedOperationException: Can not add the same measure twice on [moduleKey=:fix-missing-golint-issues1123, relative=gsm/sms_pusher_test.go, basedir=]: DefaultMeasure[component=[moduleKey=:fix-missing-golint-issues1123, relative=gsm/sms_pusher_test.go, basedir=],metric=Metric[id=,key=skipped_tests,description=Number of skipped unit tests,type=INT,direction=-1,domain=Coverage,name=Skipped Unit Tests,qualitative=true,userManaged=false,enabled=true,worstValue=,bestValue=0.0,optimizedBestValue=true,hidden=false,deleteHistoricalData=false,decimalScale=],value=0,fromCore=false]
at org.sonar.scanner.sensor.DefaultSensorStorage.saveMeasure(DefaultSensorStorage.java:255)
at org.sonar.scanner.sensor.DefaultSensorStorage.store(DefaultSensorStorage.java:213)
at org.sonar.api.batch.sensor.measure.internal.DefaultMeasure.doSave(DefaultMeasure.java:93)
at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:43)
at fr.univartois.sonargo.gotest.GoTestReportSaver.saveMeasure(GoTestReportSaver.java:69)
at fr.univartois.sonargo.gotest.GoTestReportSaver.saveMeasure(GoTestReportSaver.java:60)
at fr.univartois.sonargo.gotest.GoTestReportSaver.save(GoTestReportSaver.java:52)
at fr.univartois.sonargo.gotest.GoTestSensor.execute(GoTestSensor.java:66)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Versions

sonar: 6.2
sonar-scanner 3.0.3.778
go 1.8.3
Ubuntu Linux 4.10.0-32-generic amd6
Versions of your sonar installation (server, sonar-scanner), gometalinter, go and OS.

Additional Information

  • works fine when commenting out the three tests in gsm package:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
	<testsuite tests="6" failures="0" time="1.010" name="<obscured>/api">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="api" name="TestEnableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestCannotEnableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestDisableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestCannotDisableMobileData" time="0.000"></testcase>
		<testcase classname="api" name="TestSendSms" time="0.000"></testcase>
		<testcase classname="api" name="TestCantSendSms" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="2" failures="0" time="0.004" name="<obscured>/cpuinfo">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="cpuinfo" name="TestReadCPUInfo" time="0.000"></testcase>
		<testcase classname="cpuinfo" name="TestUniqueSerialID" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="7" failures="0" time="0.010" name="<obscured>/gsm">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="gsm" name="TestRunCommand" time="0.000"></testcase>
		<testcase classname="gsm" name="TestHelperProcess" time="0.000"></testcase>
		<testcase classname="gsm" name="TestActivate" time="0.000"></testcase>
		<testcase classname="gsm" name="TestDisable" time="0.000"></testcase>
		<!--<testcase classname="gsm" name="TestDisableSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestSendSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestCannotCreateSmsPusher" time="0.000"></testcase>-->
	</testsuite>
	<testsuite tests="13" failures="0" time="0.006" name="<obscured>/protocol">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="protocol" name="TestGetBitForEmptyString" time="0.000"></testcase>
		<testcase classname="protocol" name="TestGetBitForNotEmptyString" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionLowerThanNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionEqualWithNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestPositionGreaterThanNumber" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeMessagePayloadTooLong" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecode" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodeRawValue" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodePowerUnitData" time="0.000"></testcase>
		<testcase classname="protocol" name="TestEncodeDecodePairingRequest" time="0.000"></testcase>
		<testcase classname="protocol" name="TestDecodeNoPayload" time="0.000"></testcase>
		<testcase classname="protocol" name="TestAckPayloadNotImplemented" time="0.000"></testcase>
		<testcase classname="protocol" name="TestDefaultPayloadReturnsException" time="0.000"></testcase>
	</testsuite>
	<testsuite tests="6" failures="0" time="23.682" name="<obscured>/radio">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="radio" name="TestInitRadio" time="0.000"></testcase>
		<testcase classname="radio" name="TestStartStop" time="0.020"></testcase>
		<testcase classname="radio" name="TestSetPairingMode" time="0.000"></testcase>
		<testcase classname="radio" name="TestReceiveRawData" time="0.510"></testcase>
		<testcase classname="radio" name="TestAwaitPairingRequestTimeout" time="21.500"></testcase>
		<testcase classname="radio" name="TestPairingSuccessful" time="1.650"></testcase>
	</testsuite>
	<testsuite tests="6" failures="0" time="0.003" name="<obscured>/repository">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="repository" name="TestStoreSensor" time="0.000"></testcase>
		<testcase classname="repository" name="TestStoreField" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorByID" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetAll" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorIDForExistentSensor" time="0.000"></testcase>
		<testcase classname="repository" name="TestGetSensorIDForNewSensor" time="0.000"></testcase>
	</testsuite>
</testsuites>
  • works fine when only having tests from gsm package in test.xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
	<testsuite tests="7" failures="0" time="0.010" name="<obscured>/gsm">
		<properties>
			<property name="go.version" value="go1.8.3"></property>
		</properties>
		<testcase classname="gsm" name="TestRunCommand" time="0.000"></testcase>
		<testcase classname="gsm" name="TestHelperProcess" time="0.000"></testcase>
		<testcase classname="gsm" name="TestActivate" time="0.000"></testcase>
		<testcase classname="gsm" name="TestDisable" time="0.000"></testcase>
		<testcase classname="gsm" name="TestDisableSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestSendSms" time="0.000"></testcase>
		<testcase classname="gsm" name="TestCannotCreateSmsPusher" time="0.000"></testcase>
	</testsuite>
</testsuites>
@mariusstaicu
Copy link
Contributor Author

mariusstaicu commented Sep 1, 2017

The problem occurs when having the same test function name inside different packages.
The JUnit parser uses a map of function to fileName, which, obviously, in case of same function name X in two different packages will end up with having only one entry in the map. Then, when parsing into GoTestFiles, we end up having two identical GoTestCase objects in two different GoTestFile objects which causes the problem with the sonar runner.

@thibaultfalque
Copy link
Collaborator

Hi,
I apologize for the late reply.
I will correct, thanks for your feedback.

@mariusstaicu
Copy link
Contributor Author

Nice, thanks!

thibaultfalque pushed a commit that referenced this issue Sep 10, 2017
@thibaultfalque
Copy link
Collaborator

Hi, Please test this release.

@thibaultfalque
Copy link
Collaborator

is the problem resolved ?

@mariusstaicu
Copy link
Contributor Author

Hi, sorry for the delayed response. Currently I have another error with this new version of the plugin, trying to figure out why this happens:

java.lang.NullPointerException
at java.io.File.(File.java:277)
at org.sonar.api.batch.fs.internal.AbsolutePathPredicate.get(AbsolutePathPredicate.java:52)
at org.sonar.api.batch.fs.internal.DefaultFileSystem.inputFiles(DefaultFileSystem.java:160)
at org.sonar.api.batch.fs.internal.DefaultFileSystem.inputFile(DefaultFileSystem.java:124)
at fr.univartois.sonargo.gotest.GoTestReportSaver.save(GoTestReportSaver.java:47)
at fr.univartois.sonargo.gotest.GoTestSensor.execute(GoTestSensor.java:66)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:179)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:261)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:256)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:245)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:119)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

@mariusstaicu
Copy link
Contributor Author

Yep, it seems to be working, I can close.
Thanks, great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants