Browse Source

SONAR-17259 Remove unsupported XML tag for generic test execution report

tags/9.7.0.61563
Matteo Mara 1 year ago
parent
commit
b8f00f77ce

+ 4
- 5
server/sonar-docs/src/pages/analysis/test-coverage/generic-test.md View File

@@ -84,13 +84,13 @@ The supported format looks like this:
<file path="testx/ClassOneTest.xoo">
<testCase name="test1" duration="5"/>
<testCase name="test2" duration="500">
<skipped message="short message"/>
<skipped/>
</testCase>
<testCase name="test3" duration="100">
<failure message="short"/>
<failure/>
</testCase>
<testCase name="test4" duration="500">
<error message="short"/>
<error/>
</testCase>
</file>
</testExecutions>
@@ -110,5 +110,4 @@ It can have the following attributes/children:
* `testCase` (mandatory)
* `name` (mandatory): name of the test case
* `duration` (mandatory): long value in milliseconds
* `failure|error|skipped` (optional): if the test is not OK, report the cause with a message.
* `message` (mandatory): short message describing the cause. This attribute is mandatory but not displayed in the UI.
* `failure|error|skipped` (optional): if the test is not OK, report its status.

+ 0
- 10
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java View File

@@ -35,7 +35,6 @@ public class DefaultTestCase {
private Long durationInMs;
private Status status;
private String name;
private String message;

public String type() {
return type;
@@ -75,13 +74,4 @@ public class DefaultTestCase {
this.name = s;
return this;
}

public String message() {
return message;
}

public DefaultTestCase setMessage(String s) {
this.message = s;
return this;
}
}

+ 1
- 5
sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java View File

@@ -54,8 +54,7 @@ public class GenericTestExecutionReportParser {

private static final String NAME_ATTR = "name";
private static final String DURATION_ATTR = "duration";
private static final String MESSAGE_ATTR = "message";
public static final String OK = "ok";

public static final String ERROR = "error";
public static final String FAILURE = "failure";
public static final String SKIPPED = "skipped";
@@ -150,9 +149,6 @@ public class GenericTestExecutionReportParser {
} else if (ERROR.equals(elementName)) {
status = Status.ERROR;
}
if (Status.OK != status) {
testCase.setMessage(mandatoryAttribute(child, MESSAGE_ATTR));
}
}
testCase.setStatus(status);


+ 0
- 2
sonar-scanner-engine/src/test/java/org/sonar/scanner/deprecated/test/DefaultTestCaseTest.java View File

@@ -29,7 +29,6 @@ public class DefaultTestCaseTest {
@Test
public void getters_after_setters() {
testCase
.setMessage("message")
.setName("name")
.setType("type")
.setDurationInMs(1234L)
@@ -39,6 +38,5 @@ public class DefaultTestCaseTest {
assertThat(testCase.name()).isEqualTo("name");
assertThat(testCase.type()).isEqualTo("type");
assertThat(testCase.durationInMs()).isEqualTo(1234L);
assertThat(testCase.message()).isEqualTo("message");
}
}

+ 0
- 29
sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java View File

@@ -116,34 +116,6 @@ public class GenericTestExecutionReportParserTest {
parseUnitTestReport("<unitTest version=\"2\"></unitTest>");
}

@Test(expected = MessageException.class)
public void unittest_duration_in_testCase_should_be_a_number() throws Exception {
addFileToFs(setupFile("file1"));
parseUnitTestReport("<unitTest version=\"1\"><file path=\"file1\">"
+ "<testCase name=\"test1\" duration=\"aaa\"/></file></unitTest>");
}

@Test(expected = MessageException.class)
public void unittest_failure_should_have_a_message() throws Exception {
addFileToFs(setupFile("file1"));
parseUnitTestReport("<unitTest version=\"1\"><file path=\"file1\">"
+ "<testCase name=\"test1\" duration=\"2\"><failure /></testCase></file></unitTest>");
}

@Test(expected = MessageException.class)
public void unittest_error_should_have_a_message() throws Exception {
addFileToFs(setupFile("file1"));
parseUnitTestReport("<unitTest version=\"1\"><file path=\"file1\">"
+ "<testCase name=\"test1\" duration=\"2\"><error /></testCase></file></unitTest>");
}

@Test(expected = MessageException.class)
public void unittest_skipped_should_have_a_message() throws Exception {
addFileToFs(setupFile("file1"));
parseUnitTestReport("<unitTest version=\"1\"><file path=\"file1\">"
+ "<testCase name=\"test1\" duration=\"2\"><skipped notmessage=\"\"/></testCase></file></unitTest>");
}

@Test(expected = MessageException.class)
public void unittest_duration_in_testCase_should_not_be_negative() throws Exception {
addFileToFs(setupFile("file1"));
@@ -187,7 +159,6 @@ public class GenericTestExecutionReportParserTest {
DefaultTestCase testCase = mock(DefaultTestCase.class);
when(testCase.setDurationInMs(anyLong())).thenReturn(testCase);
when(testCase.setStatus(any(DefaultTestCase.Status.class))).thenReturn(testCase);
when(testCase.setMessage(anyString())).thenReturn(testCase);
when(testCase.setType(anyString())).thenReturn(testCase);
return testCase;
}

+ 3
- 3
sonar-scanner-engine/src/test/resources/org/sonar/scanner/genericcoverage/unittest.xml View File

@@ -3,13 +3,13 @@
<file path="src/main/java/com/example/ClassWithoutBranch.java">
<testCase name="test1" duration="5"/>
<testCase name="test2" duration="500">
<skipped message="short message">other</skipped>
<skipped>other</skipped>
</testCase>
<testCase name="test3" duration="100">
<failure message="short">stacktrace</failure>
<failure>stacktrace</failure>
</testCase>
<testCase name="test4" duration="500">
<error message="short">stacktrace</error>
<error>stacktrace</error>
</testCase>
</file>
</unitTest>

+ 3
- 3
sonar-scanner-engine/src/test/resources/org/sonar/scanner/genericcoverage/unittest2.xml View File

@@ -2,14 +2,14 @@
<file path="src/main/java/com/example/EmptyClass.java"/>
<file path="src/main/java/com/example/ClassWithBranches.java">
<testCase name="test1" duration="500">
<skipped message="short message">other</skipped>
<skipped>other</skipped>
</testCase>
<testCase name="test2" duration="300">
<failure message="short">stacktrace</failure>
<failure>stacktrace</failure>
</testCase>
<testCase name="test3" duration="300" />
<testCase name="test4" duration="300">
<ok message="aaa">long</ok>
<ok>long</ok>
</testCase>
</file>
</unitTest>

+ 3
- 3
sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/unittest.xml View File

@@ -2,13 +2,13 @@
<file path="testx/ClassOneTest.xoo">
<testCase name="test1" duration="5"/>
<testCase name="test2" duration="500">
<skipped message="short message">other</skipped>
<skipped>other</skipped>
</testCase>
<testCase name="test3" duration="100">
<failure message="short">stacktrace</failure>
<failure>stacktrace</failure>
</testCase>
<testCase name="test4" duration="500">
<error message="short">stacktrace</error>
<error>stacktrace</error>
</testCase>
</file>
</testExecutions>

+ 1
- 1
sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/unittest2.xml View File

@@ -2,7 +2,7 @@
<file path="testx/ClassOneTest.xoo">
<testCase name="test1b" duration="5"/>
<testCase name="test2" duration="500">
<skipped message="short message">other</skipped>
<skipped>other</skipped>
</testCase>
</file>
</testExecutions>

Loading…
Cancel
Save