From d2f3ffeb7174776480e0999120a71234c2537762 Mon Sep 17 00:00:00 2001 From: agudian Date: Sun, 30 Dec 2012 00:30:13 +0100 Subject: [PATCH] [SUREFIRE-943] fix test name in XML report Added an integration test for the issue --- .../its/jiras/Surefire943ReportContentIT.java | 60 +++++++++++++++++++ .../surefire-943-report-content/pom.xml | 42 +++++++++++++ .../test/java/org/sample/module/My1Test.java | 23 +++++++ .../test/java/org/sample/module/My2Test.java | 22 +++++++ .../test/java/org/sample/module/My3Test.java | 22 +++++++ .../junitcore/NonConcurrentRunListener.java | 16 ++--- 6 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml create mode 100644 surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java create mode 100644 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/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 0000000000..166d3e916c --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java @@ -0,0 +1,60 @@ +package org.apache.maven.surefire.its.jiras; + +import java.io.FileNotFoundException; +import java.io.FileReader; + +import org.apache.maven.shared.utils.xml.Xpp3Dom; +import org.apache.maven.shared.utils.xml.Xpp3DomBuilder; +import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; +import org.apache.maven.surefire.its.fixture.OutputValidator; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.codehaus.plexus.util.xml.Xpp3DomUtils; +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 ); + } + } + } + +} 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 0000000000..ccdea726ff --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + dummy + 1.0-SNAPSHOT + dummy + surefire-943-report-content + + + 2.13 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + org.apache.maven.surefire + surefire-junit47 + ${surefire.version} + + + + + + + + + + junit + junit + test + 4.11 + + + 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 0000000000..b2a2919076 --- /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() + { + + } +} 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 0000000000..7f70c76025 --- /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() + { + + } +} 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 0000000000..bb2a06bcf7 --- /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() + { + + } +} 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 835f46c17a..31ad8c7126 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 @@ -59,16 +59,16 @@ public synchronized void writeTestOutput( byte[] buf, int off, int len, boolean 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 public void testStarted( Description description ) throws Exception @@ -78,11 +78,11 @@ public void testStarted( Description description ) 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 +130,7 @@ public void testRunFinished( Result result ) { if ( lastFinishedDescription != null ) { - reporter.testSetCompleted( createReportEntry( lastFinishedDescription ) ); + reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) ); lastFinishedDescription = null; } }