You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2015/12/26 20:42:04 UTC
maven-surefire git commit: [SUREFIRE-1135] Improve ignore message for
TestNG
Repository: maven-surefire
Updated Branches:
refs/heads/master c922c040b -> 33105af2e
[SUREFIRE-1135] Improve ignore message for TestNG
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/33105af2
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/33105af2
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/33105af2
Branch: refs/heads/master
Commit: 33105af2ee5b5de0f99e39b74a2f2cc78c0588a3
Parents: c922c04
Author: Tibor17 <ti...@lycos.com>
Authored: Sat Dec 26 20:41:34 2015 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Sat Dec 26 20:41:34 2015 +0100
----------------------------------------------------------------------
.../its/jiras/Surefire1135ImproveIgnoreMessageForTestNGIT.java | 1 +
.../surefire-1135-improve-ignore-message-for-testng/pom.xml | 1 +
.../src/test/java/testng/SkipExceptionReportTest.java | 1 +
.../java/org/apache/maven/surefire/testng/TestNGReporter.java | 5 ++++-
4 files changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/33105af2/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1135ImproveIgnoreMessageForTestNGIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1135ImproveIgnoreMessageForTestNGIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1135ImproveIgnoreMessageForTestNGIT.java
new file mode 100644
index 0000000..131244f
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1135ImproveIgnoreMessageForTestNGIT.java
@@ -0,0 +1 @@
+package org.apache.maven.surefire.its.jiras;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import static org.apache.maven.shared.utils.xml.Xpp3DomBuilder.build;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.
assertThat;
import java.io.FileNotFoundException;
import org.apache.maven.shared.utils.xml.Xpp3Dom;
import org.apache.maven.surefire.its.fixture.OutputValidator;
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
import org.junit.Test;
/**
* Test surefire-report on TestNG test
*
* @author <a href="mailto:michal.bocek@gmail.com">Michal Bocek</a>
*/
public class Surefire1135ImproveIgnoreMessageForTestNGIT
extends SurefireJUnit4IntegrationTestCase
{
private enum ResultType
{
SKIPPED( "skipped" ), FAILURE( "failure" );
private final String type;
ResultType(String type)
{
this.type = type;
}
public String getType() {
return type;
}
}
@Test
public void testNgReport688() throws Exception {
testNgReport( "6.8.8", ResultType.SKIPPED,
"Skip test",
/*"org.testng.SkipException"*
/ null,
/*"SkipExceptionReportTest.java:30"*/ null );
}
@Test
public void testNgReport57() throws Exception {
testNgReport( "5.7", ResultType.SKIPPED,
"Skip test",
/*"org.testng.SkipException"*/ null,
/*"SkipExceptionReportTest.java:30"*/ null );
}
private void testNgReport( String version, ResultType resultType, String message, String type, String stackTrace )
throws Exception
{
OutputValidator outputValidator =
runTest( version, resultType, "/surefire-1135-improve-ignore-message-for-testng" );
Xpp3Dom[] children = readTests( outputValidator, "testng.SkipExceptionReportTest" );
assertThat( "Report should contains only one test case", children.length, is( 1 ) );
Xpp3Dom test = children[0];
assertThat( "Not expected classname", test.getAttribute( "cla
ssname" ),
is( "testng.SkipExceptionReportTest" ) );
assertThat( "Not expected test name", test.getAttribute( "name" ), is( "testSkipException" ) );
children = test.getChildren( resultType.getType() );
assertThat( "Test should contains only one " + resultType.getType() + " element", children,
is( arrayWithSize( 1 ) ) );
Xpp3Dom result = children[0];
if ( message == null )
{
assertThat( "Subelement message attribute must be null", result.getAttribute( "message" ),
is( nullValue() ) );
}
else
{
assertThat( "Subelement should contains message attribute", result.getAttribute( "message" ),
is( message ) );
}
if ( type == null )
{
assertThat( "Subelement type attribute must be null", result.getAttribute( "type" ), is( nullValue() ) );
}
else
{
assertThat( "Subelement should contains type attribute", result.getAttribute( "type" ), is( type ) );
}
if ( stackTrace == null )
{
assertThat( "Element body must be null", result.getValue() , isEmptyOrNullString() );
}
else
{
assertThat( "Element body must contains", result.getValue(), containsString( stackTrace ) );
}
}
private OutputValidator runTest( String version, ResultType resultType, String resource )
{
int skipped = ResultType.SKIPPED.equals( resultType ) ? 1 : 0;
int failure = ResultType.FAILURE.equals( resultType ) ? 1 : 0;
return unpack( resource )
.resetInitialGoals( version )
.addSurefireReportGoal()
.executeCurrentGoals()
.assertTestSuiteResults( 1, 0, failure, skipped );
}
private static Xpp3Dom[] readTests( OutputV
alidator validator, String className )
throws FileNotFoundException
{
Xpp3Dom testResult =
build( validator.getSurefireReportsXmlFile( "TEST-" + className + ".xml" ).getFileInputStream(),
"UTF-8"
);
return testResult.getChildren( "testcase" );
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/33105af2/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/pom.xml b/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/pom.xml
new file mode 100644
index 0000000..4a88e6d
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/pom.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi
:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>surefire-1135-improve-ignore-message-for-testng</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Surefire 1135</name>
<profiles>
<profile>
<id>testng-old</id>
<activation>
<property><name>testNgClassifier</name></property>
</activation>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testNgVersion}</version>
<classifier>${testNgClassifier}</classifier>
</dependency>
</dependencies>
</profile>
<profile>
<id>testng-new</id>
<activation>
<property><name>!testNgClassifier</name></property>
</activation>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<ar
tifactId>testng</artifactId>
<version>${testNgVersion}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<properties>
<testNgVersion>5.7</testNgVersion>
<testNgClassifier>jdk15</testNgClassifier>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<test>SkipExceptionReportTest</test>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/33105af2/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/src/test/java/testng/SkipExceptionReportTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/src/test/java/testng/SkipExceptionReportTest.java b/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/src/test/java/testng/SkipExceptionReportTest.java
new file mode 100644
index 0000000..abb555f
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-1135-improve-ignore-message-for-testng/src/test/java/testng/SkipExceptionReportTest.java
@@ -0,0 +1 @@
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package testng;
import org.testng.annotations.Test;
import org.testng.SkipException;
public class SkipExceptionReportTest
{
@Test
public void testSkipException()
{
throw new SkipException("Skip test");
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/33105af2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
index bb4f411..c6790be 100644
--- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
+++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
@@ -31,6 +31,7 @@ import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
+import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
import static org.apache.maven.surefire.report.SimpleReportEntry.withException;
/**
@@ -97,7 +98,9 @@ public class TestNGReporter
public void onTestSkipped( ITestResult result )
{
- ReportEntry report = new SimpleReportEntry( getSource( result ), getUserFriendlyTestName( result ) );
+ Throwable t = result.getThrowable();
+ String reason = t == null ? null : t.getMessage();
+ ReportEntry report = ignored( getSource( result ), getUserFriendlyTestName( result ), reason );
reporter.testSkipped( report );
}