You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/12/31 11:51:03 UTC
git commit: [SUREFIRE-943] fix test name in XML report
Updated Branches:
refs/heads/master 49eedd6d0 -> 5bfd27173
[SUREFIRE-943] fix test name in XML report
Added an integration test for the issue
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/5bfd2717
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/5bfd2717
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/5bfd2717
Branch: refs/heads/master
Commit: 5bfd2717377ae52bb1a2e0be65f94723ca011b83
Parents: 49eedd6
Author: agudian <an...@gmail.com>
Authored: Sun Dec 30 00:30:13 2012 +0100
Committer: Kristian Rosenvold <kr...@apache.org>
Committed: Mon Dec 31 11:50:02 2012 +0100
----------------------------------------------------------------------
.../its/jiras/Surefire943ReportContentIT.java | 76 +++++++++++++++
.../resources/surefire-943-report-content/pom.xml | 42 ++++++++
.../src/test/java/org/sample/module/My1Test.java | 23 +++++
.../src/test/java/org/sample/module/My2Test.java | 22 ++++
.../src/test/java/org/sample/module/My3Test.java | 22 ++++
.../junitcore/NonConcurrentRunListener.java | 15 ++--
6 files changed, 193 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
new file mode 100644
index 0000000..8e68d28
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
@@ -0,0 +1,76 @@
+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 java.io.FileNotFoundException;
+import org.apache.maven.shared.utils.xml.Xpp3Dom;
+import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Surefire943ReportContentIT
+ extends SurefireJUnit4IntegrationTestCase
+{
+
+ @Test
+ public void test()
+ throws Exception
+ {
+ OutputValidator validator = unpack( "surefire-943-report-content" ).maven().withFailure().executeTest();
+ validator.assertTestSuiteResults( 6, 0, 3, 0 );
+
+ validate( validator, "org.sample.module.My1Test" );
+ validate( validator, "org.sample.module.My2Test" );
+ validate( validator, "org.sample.module.My3Test" );
+ }
+
+ private void validate( OutputValidator validator, String className )
+ throws FileNotFoundException
+ {
+ Xpp3Dom testResult =
+ Xpp3DomBuilder.build( validator.getSurefireReportsFile( "TEST-" + className + ".xml" ).getFileInputStream(),
+ "UTF-8" );
+ Xpp3Dom[] children = testResult.getChildren( "testcase" );
+
+ Assert.assertEquals( 2, children.length );
+
+ for ( Xpp3Dom child : children )
+ {
+ Assert.assertEquals( className, child.getAttribute( "classname" ) );
+
+ if ( "alwaysSuccessful".equals( child.getAttribute( "name" ) ) )
+ {
+ Assert.assertEquals( "Expected no failures for method alwaysSuccessful for " + className, 0,
+ child.getChildCount() );
+ }
+ else
+ {
+ Assert.assertEquals( "Expected methods \"alwaysSuccessful\" and \"fails\" in " + className, "fails",
+ child.getAttribute( "name" ) );
+ Assert.assertEquals( "Expected failure description for method \"fails\" in " + className, 1,
+ child.getChildren( "failure" ).length );
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml b/surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml
new file mode 100644
index 0000000..ccdea72
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>dummy</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>dummy</artifactId>
+ <name>surefire-943-report-content</name>
+
+ <properties>
+ <surefire.version>2.13</surefire.version>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit47</artifactId>
+ <version>${surefire.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ <version>4.11</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
new file mode 100644
index 0000000..b2a2919
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
@@ -0,0 +1,23 @@
+package org.sample.module;
+
+import static org.junit.Assert.fail;
+
+import java.lang.management.ManagementFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class My1Test
+{
+ @Test
+ public void fails()
+ {
+ fail( "Always fails" );
+ }
+
+ @Test
+ public void alwaysSuccessful()
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
new file mode 100644
index 0000000..7f70c76
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
@@ -0,0 +1,22 @@
+package org.sample.module;
+
+import static org.junit.Assert.fail;
+
+import java.lang.management.ManagementFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class My2Test {
+ @Test
+ public void fails()
+ {
+ fail( "Always fails" );
+ }
+
+ @Test
+ public void alwaysSuccessful()
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
new file mode 100644
index 0000000..bb2a06b
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
@@ -0,0 +1,22 @@
+package org.sample.module;
+
+import static org.junit.Assert.fail;
+
+import java.lang.management.ManagementFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class My3Test {
+ @Test
+ public void fails()
+ {
+ fail( "Always fails" );
+ }
+
+ @Test
+ public void alwaysSuccessful()
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/5bfd2717/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
index 835f46c..240a40f 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
@@ -24,6 +24,7 @@ import org.apache.maven.surefire.report.ConsoleOutputReceiver;
import org.apache.maven.surefire.report.RunListener;
import org.apache.maven.surefire.report.SimpleReportEntry;
import org.apache.maven.surefire.testset.TestSetFailedException;
+
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
@@ -59,14 +60,14 @@ public class NonConcurrentRunListener
protected SimpleReportEntry createReportEntry( Description description )
{
- return new SimpleReportEntry( description.getClassName(), description.getClassName(),
+ return new SimpleReportEntry( description.getClassName(), description.getDisplayName(),
(int) ( System.currentTimeMillis() - startTime ) );
}
-
- public String getClassName( Description description )
+ protected SimpleReportEntry createReportEntryForTestSet( Description description )
{
- return description.getClass().getSimpleName();
+ return new SimpleReportEntry( description.getClassName(), description.getClassName(),
+ (int) ( System.currentTimeMillis() - startTime ) );
}
@Override
@@ -78,11 +79,11 @@ public class NonConcurrentRunListener
currentTestClass = description.getTestClass();
if ( lastFinishedDescription != null )
{
- reporter.testSetCompleted( createReportEntry( lastFinishedDescription ) );
+ reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) );
lastFinishedDescription = null;
}
startTime = System.currentTimeMillis();
- reporter.testSetStarting( createReportEntry( description ) );
+ reporter.testSetStarting( createReportEntryForTestSet( description ) );
}
super.testStarted( description );
}
@@ -130,7 +131,7 @@ public class NonConcurrentRunListener
{
if ( lastFinishedDescription != null )
{
- reporter.testSetCompleted( createReportEntry( lastFinishedDescription ) );
+ reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) );
lastFinishedDescription = null;
}
}