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/08/17 15:53:41 UTC
svn commit: r1374259 [1/2] - in /maven/surefire/trunk:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/
maven-surefire-common/src/main/java/org/apache/mav...
Author: krosenvold
Date: Fri Aug 17 13:53:40 2012
New Revision: 1374259
URL: http://svn.apache.org/viewvc?rev=1374259&view=rev
Log:
o Removed the reporter interface
Added:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
- copied, changed from r1373909, maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/XMLReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/pom.xml
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test1.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test2.java
Removed:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/AbstractTextReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/MulticastingReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Reporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/XMLReporter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/XMLReporterTest.java
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/ConsoleOutputFileReporterTest.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java Fri Aug 17 13:53:40 2012
@@ -19,9 +19,13 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-import org.apache.maven.plugin.surefire.report.*;
-import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
+import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
+import org.apache.maven.plugin.surefire.report.ConsoleReporter;
+import org.apache.maven.plugin.surefire.report.DirectConsoleOutput;
+import org.apache.maven.plugin.surefire.report.FileReporter;
+import org.apache.maven.plugin.surefire.report.StatelessXmlReporter;
import org.apache.maven.plugin.surefire.report.TestcycleConsoleOutputReceiver;
+import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import java.io.File;
import java.io.PrintStream;
@@ -61,9 +65,9 @@ public class StartupReportConfiguration
private final Properties testVmSystemProperties = new Properties();
- public static final String BRIEF_REPORT_FORMAT = AbstractTextReporter.BRIEF;
+ public static final String BRIEF_REPORT_FORMAT = ConsoleReporter.BRIEF;
- public static final String PLAIN_REPORT_FORMAT = AbstractTextReporter.PLAIN;
+ public static final String PLAIN_REPORT_FORMAT = ConsoleReporter.PLAIN;
public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
boolean redirectTestOutputToFile, boolean disableXmlReport,
@@ -133,11 +137,11 @@ public class StartupReportConfiguration
return reportsDirectory;
}
- public XMLReporter instantiateXmlReporter()
+ public StatelessXmlReporter instantiateStatelessXmlReporter()
{
if ( !isDisableXmlReport() )
{
- return new XMLReporter( reportsDirectory, reportNameSuffix );
+ return new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace );
}
return null;
}
@@ -148,30 +152,34 @@ public class StartupReportConfiguration
{
if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
{
- return new FileReporter( AbstractTextReporter.BRIEF, reportsDirectory, getReportNameSuffix() );
+ return new FileReporter( reportsDirectory, getReportNameSuffix() );
}
else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
{
- return new FileReporter( AbstractTextReporter.PLAIN, reportsDirectory, getReportNameSuffix() );
+ return new FileReporter( reportsDirectory, getReportNameSuffix() );
}
}
return null;
}
+ public boolean isBriefOrPlainFormat()
+ {
+ return BRIEF_REPORT_FORMAT.equals( getReportFormat() ) || PLAIN_REPORT_FORMAT.equals( getReportFormat() );
+ }
public ConsoleReporter instantiateConsoleReporter()
{
if ( isUseFile() )
{
- return isPrintSummary() ? new ConsoleReporter( AbstractTextReporter.SUMMARY ) : null;
+ return isPrintSummary() ? new ConsoleReporter() : null;
}
else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
{
- return new ConsoleReporter( AbstractTextReporter.BRIEF );
+ return new ConsoleReporter();
}
else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
{
- return new ConsoleReporter( AbstractTextReporter.PLAIN );
+ return new ConsoleReporter();
}
return null;
}
@@ -230,8 +238,4 @@ public class StartupReportConfiguration
return originalSystemOut;
}
- public PrintStream getOriginalSystemErr()
- {
- return originalSystemErr;
- }
}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java Fri Aug 17 13:53:40 2012
@@ -23,7 +23,11 @@ import org.apache.maven.surefire.report.
import org.apache.maven.surefire.report.ReporterException;
import org.apache.maven.surefire.util.NestedRuntimeException;
-import java.io.*;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
/**
* Surefire output consumer proxy that writes test output to a {@link java.io.File} for each test suite.
@@ -65,11 +69,6 @@ public class ConsoleOutputFileReporter
}
}
- public void writeMessage( byte[] b, int off, int len )
- {
- writeTestOutput( b, off, len, true );
- }
-
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
{
try
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java Fri Aug 17 13:53:40 2012
@@ -19,21 +19,27 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
+
import java.io.BufferedOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterException;
+import java.util.List;
/**
* Base class for console reporters.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @author Kristian Rosenvold
*/
public class ConsoleReporter
- extends AbstractTextReporter
{
+ public static final String BRIEF = "brief";
+
+ public static final String PLAIN = "plain";
+
private static final String TEST_SET_STARTING_PREFIX = "Running ";
private static final String TEST_SET_STARTING_GROUP_PREFIX = " (of ";
@@ -44,9 +50,12 @@ public class ConsoleReporter
private static final PrintStream ORIGINAL_SYSTEM_OUT = System.out;
- public ConsoleReporter( String format )
+ private final PrintWriter writer;
+
+
+ public ConsoleReporter()
{
- super( getPrintWriter(), format );
+ this.writer = getPrintWriter();
}
private static PrintWriter getPrintWriter()
@@ -61,6 +70,49 @@ public class ConsoleReporter
writeMessage( getTestSetStartingMessage( report ) );
}
+ public void writeMessage( String message )
+ {
+ if ( writer != null )
+ {
+ writer.print( message );
+
+ writer.flush();
+ }
+ }
+
+ public void writeLnMessage( String message )
+ {
+ if ( writer != null )
+ {
+ writer.println( message );
+
+ writer.flush();
+ }
+ }
+
+ public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults )
+ throws ReporterException
+ {
+ writeMessage( testSetStats.getTestSetSummary( report ) );
+
+ if ( testResults != null )
+ {
+ for ( String testResult : testResults )
+ {
+ writeLnMessage( testResult );
+ }
+ }
+ }
+
+
+ public void reset()
+ {
+ if ( writer != null )
+ {
+ writer.flush();
+ }
+ }
+
/**
* Get the test set starting message for a report.
* eg. "Running org.foo.BarTest ( of group )"
@@ -85,4 +137,5 @@ public class ConsoleReporter
return message.toString();
}
+
}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java Fri Aug 17 13:53:40 2012
@@ -19,12 +19,9 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-import java.util.ArrayList;
-import java.util.List;
import org.apache.maven.plugin.surefire.StartupReportConfiguration;
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
-import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.ReporterFactory;
import org.apache.maven.surefire.report.RunListener;
import org.apache.maven.surefire.report.RunStatistics;
@@ -40,11 +37,10 @@ import org.apache.maven.surefire.suite.R
public class DefaultReporterFactory
implements ReporterFactory
{
- private final ReporterConfiguration reporterConfiguration;
private final RunStatistics globalStats = new RunStatistics();
- private final MulticastingReporter multicastingReporter;
+ private final ConsoleReporter multicastingReporter;
private final StartupReportConfiguration reportConfiguration;
@@ -53,45 +49,20 @@ public class DefaultReporterFactory
public DefaultReporterFactory( StartupReportConfiguration reportConfiguration )
{
this.reportConfiguration = reportConfiguration;
- this.reporterConfiguration = getReporterConfiguration();
- multicastingReporter = new MulticastingReporter( instantiateReports() );
+ multicastingReporter = reportConfiguration.instantiateConsoleReporter();
this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter();
runStarting();
}
- private ReporterConfiguration getReporterConfiguration()
- {
- //noinspection BooleanConstructorCall
- return new ReporterConfiguration( reportConfiguration.getReportsDirectory(),
- reportConfiguration.isTrimStackTrace() );
- }
-
public RunListener createReporter()
{
return new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(),
reportConfiguration.instantiateFileReporter(),
- reportConfiguration.instantiateXmlReporter(),
- reportConfiguration.instantiateConsoleOutputFileReporter(),
- statisticsReporter, globalStats, reportConfiguration.isTrimStackTrace(),
- AbstractTextReporter.PLAIN.equals(reportConfiguration.getReportFormat()));
- }
-
- private List<Reporter> instantiateReports()
- {
- List<Reporter> result = new ArrayList<Reporter>();
- addIfNotNull( result, reportConfiguration.instantiateConsoleReporter() );
- addIfNotNull( result, reportConfiguration.instantiateFileReporter() );
- addIfNotNull( result, reportConfiguration.instantiateXmlReporter() );
- addIfNotNull( result, statisticsReporter );
- return result;
- }
-
- private void addIfNotNull( List<Reporter> result, Reporter reporter )
- {
- if ( reporter != null )
- {
- result.add( reporter );
- }
+ reportConfiguration.instantiateStatelessXmlReporter(),
+ reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter,
+ globalStats, reportConfiguration.isTrimStackTrace(),
+ ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ),
+ reportConfiguration.isBriefOrPlainFormat() );
}
public RunResult close()
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java Fri Aug 17 13:53:40 2012
@@ -19,20 +19,22 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterException;
+import java.util.List;
/**
* Base class for file reporters.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @author Kristian Rosenvold
*/
public class FileReporter
- extends AbstractTextReporter
{
private final File reportsDirectory;
@@ -40,15 +42,14 @@ public class FileReporter
private final String reportNameSuffix;
- public FileReporter( String format, File reportsDirectory, String reportNameSuffix )
+ public FileReporter( File reportsDirectory, String reportNameSuffix )
{
- super( format );
this.reportsDirectory = reportsDirectory;
this.deleteOnStarting = false;
this.reportNameSuffix = reportNameSuffix;
}
- public void testSetStarting( ReportEntry report )
+ private PrintWriter testSetStarting( ReportEntry report )
throws ReporterException
{
File reportFile = getReportFile( reportsDirectory, report.getName(), reportNameSuffix, ".txt" );
@@ -74,7 +75,7 @@ public class FileReporter
writer.println( "-------------------------------------------------------------------------------" );
- setWriter( writer );
+ return writer;
}
catch ( IOException e )
{
@@ -98,15 +99,22 @@ public class FileReporter
return reportFile;
}
- public void testSetCompleted( ReportEntry report, TestSetStats testSetStats )
+ public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults )
throws ReporterException
{
- super.testSetCompleted( report, testSetStats );
+ PrintWriter writer = testSetStarting( report );
+ writer.print( testSetStats.getTestSetSummary( report ) );
+
+ if ( testResults != null )
+ {
+ for ( String testResult : testResults )
+ {
+ writer.println( testResult );
+ }
+ }
writer.flush();
writer.close();
-
- writer = null;
}
}
Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java?rev=1374259&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java Fri Aug 17 13:53:40 2012
@@ -0,0 +1,29 @@
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * 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.
+ */
+
+public enum ReportEntryType
+{
+ error,
+ failure,
+ skipped,
+ success
+
+}
Copied: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java (from r1373909, maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/XMLReporter.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java?p2=maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java&p1=maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/XMLReporter.java&r1=1373909&r2=1374259&rev=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/XMLReporter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java Fri Aug 17 13:53:40 2012
@@ -1,386 +1,305 @@
-package org.apache.maven.plugin.surefire.report;
-
-/*
- * 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.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterException;
-import org.apache.maven.surefire.report.SafeThrowable;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.Xpp3DomWriter;
-
-/**
- * XML format reporter writing to <code>TEST-<i>reportName</i>[-<i>suffix</i>].xml</code> file like written and read
- * by Ant's <a href="http://ant.apache.org/manual/Tasks/junit.html"><code><junit></code></a> and
- * <a href="http://ant.apache.org/manual/Tasks/junitreport.html"><code><junitreport></code></a> tasks,
- * then supported by many tools like CI servers.
- * <p/>
- * <pre><?xml version="1.0" encoding="UTF-8"?>
- * <testsuite name="<i>suite name</i>" [group="<i>group</i>"] tests="<i>0</i>" failures="<i>0</i>" errors="<i>0</i>" skipped="<i>0</i>" time="<i>0,###.###</i>">
- * <properties>
- * <property name="<i>name</i>" value="<i>value</i>"/>
- * [...]
- * </properties>
- * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]"/>
- * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
- * <<b>error</b> message="<i>message</i>" type="<i>exception class name</i>"><i>stacktrace</i></error>
- * <system-out><i>system out content (present only if not empty)</i></system-out>
- * <system-err><i>system err content (present only if not empty)</i></system-err>
- * </testcase>
- * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
- * <<b>failure</b> message="<i>message</i>" type="<i>exception class name</i>"><i>stacktrace</i></failure>
- * <system-out><i>system out content (present only if not empty)</i></system-out>
- * <system-err><i>system err content (present only if not empty)</i></system-err>
- * </testcase>
- * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
- * <<b>skipped</b>/>
- * </testcase>
- * [...]</pre>
- *
- * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
- * @version $Id$
- * @see <a href="http://wiki.apache.org/ant/Proposals/EnhancedTestReports">Ant's format enhancement proposal</a>
- * (not yet implemented by Ant 1.8.2)
- */
-public class XMLReporter
- implements Reporter
-{
- private static final String LS = System.getProperty( "line.separator" );
-
- private final File reportsDirectory;
-
- private final boolean deleteOnStarting;
-
- private final String reportNameSuffix;
-
- private final List<Xpp3Dom> results = Collections.synchronizedList( new ArrayList<Xpp3Dom>() );
-
- private int elapsed = 0;
-
- public XMLReporter( File reportsDirectory )
- {
- this( reportsDirectory, null );
- }
-
- public XMLReporter( File reportsDirectory, String reportNameSuffix )
- {
- this.reportsDirectory = reportsDirectory;
- this.deleteOnStarting = false;
- this.reportNameSuffix = reportNameSuffix;
- }
-
-
- public void writeMessage( String message )
- {
- }
-
- public void testSetStarting( ReportEntry report )
- throws ReporterException
- {
- if ( deleteOnStarting )
- {
- final File reportFile = getReportFile( report );
- deleteIfExisting( reportFile );
- }
- }
-
- void deleteIfExisting( File reportFile )
- {
- if ( reportFile.exists() )
- {
- //noinspection ResultOfMethodCallIgnored
- reportFile.delete();
- }
- }
-
-
- public void testSetCompleted( ReportEntry report, TestSetStats testSetStats )
- throws ReporterException
- {
-
- Xpp3Dom testSuite = createTestSuiteElement( report, testSetStats );
-
- showProperties( testSuite );
-
- testSuite.setAttribute( "tests", String.valueOf( testSetStats.getCompletedCount() ) );
-
- testSuite.setAttribute( "errors", String.valueOf( testSetStats.getErrors() ) );
-
- testSuite.setAttribute( "skipped", String.valueOf( testSetStats.getSkipped() ) );
-
- testSuite.setAttribute( "failures", String.valueOf( testSetStats.getFailures() ) );
-
- for ( Object result : results )
- {
- Xpp3Dom testcase = (Xpp3Dom) result;
- testSuite.addChild( testcase );
- }
-
- File reportFile = getReportFile( report );
-
- File reportDir = reportFile.getParentFile();
-
- //noinspection ResultOfMethodCallIgnored
- reportDir.mkdirs();
-
- PrintWriter writer = null;
-
- try
- {
- writer = new PrintWriter(
- new BufferedWriter( new OutputStreamWriter( new FileOutputStream( reportFile ), "UTF-8" ) ) );
-
- writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + LS );
-
- Xpp3DomWriter.write( new PrettyPrintXMLWriter( writer ), testSuite );
- }
- catch ( UnsupportedEncodingException e )
- {
- throw new ReporterException( "Unable to use UTF-8 encoding", e );
- }
- catch ( FileNotFoundException e )
- {
- throw new ReporterException( "Unable to create file: " + e.getMessage(), e );
- }
-
- finally
- {
- IOUtil.close( writer );
- }
- }
-
- private File getReportFile( ReportEntry report )
- {
- File reportFile;
-
- if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
- {
- reportFile = new File( reportsDirectory, "TEST-" + report.getName() + "-" + reportNameSuffix + ".xml" );
- }
- else
- {
- reportFile = new File( reportsDirectory, "TEST-" + report.getName() + ".xml" );
- }
-
- return reportFile;
- }
-
- public void testSucceeded( ReportEntry report, TestSetStats testSetStats )
- {
- Xpp3Dom testCase = createTestElement( report, testSetStats );
-
- results.add( testCase );
- }
-
- public void testStarting( ReportEntry report )
- {
- }
-
- static String getReportName( ReportEntry report )
- {
- final int i = report.getName().lastIndexOf( "(" );
- return i > 0 ? report.getName().substring( 0, i ) : report.getName();
- }
-
- private Xpp3Dom createTestElement( ReportEntry report, TestSetStats runTime )
- {
- elapsed += report.getElapsed();
- Xpp3Dom testCase = new Xpp3Dom( "testcase" );
- testCase.setAttribute( "name", getReportName( report ) );
- if ( report.getGroup() != null )
- {
- testCase.setAttribute( "group", report.getGroup() );
- }
- if ( report.getSourceName() != null )
- {
- if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
- {
- testCase.setAttribute( "classname", report.getSourceName() + "(" + reportNameSuffix + ")" );
- }
- else
- {
- testCase.setAttribute( "classname", report.getSourceName() );
- }
- }
- testCase.setAttribute( "time", runTime.elapsedTimeAsString( runTime.getActualRunTime( report ) ) );
- return testCase;
- }
-
- private Xpp3Dom createTestSuiteElement( ReportEntry report, TestSetStats testSetStats )
- {
- Xpp3Dom testCase = new Xpp3Dom( "testsuite" );
-
- if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
- {
- testCase.setAttribute( "name", getReportName( report ) + "(" + reportNameSuffix + ")" );
- }
- else
- {
- testCase.setAttribute( "name", getReportName( report ) );
- }
- if ( report.getGroup() != null )
- {
- testCase.setAttribute( "group", report.getGroup() );
- }
- long runTime = elapsed > 0 ? elapsed : ( System.currentTimeMillis() - testSetStats.getTestSetStartAt() );
- testCase.setAttribute( "time", testSetStats.elapsedTimeAsString( runTime ) );
- return testCase;
- }
-
- public void testError( ReportEntry report, String stdOut, String stdErr, TestSetStats testSetStats )
- {
- writeTestProblems( report, stdOut, stdErr, "error", testSetStats );
- }
-
- public void testFailed( ReportEntry report, String stdOut, String stdErr, TestSetStats testSetStats )
- {
- writeTestProblems( report, stdOut, stdErr, "failure", testSetStats );
- }
-
- public void testSkipped( ReportEntry report, TestSetStats testSetStats )
- {
- writeTestProblems( report, null, null, "skipped", testSetStats );
- }
-
- private void writeTestProblems( ReportEntry report, String stdOut, String stdErr, String name,
- TestSetStats elapsedForTest )
- {
-
- Xpp3Dom testCase = createTestElement( report, elapsedForTest );
-
- Xpp3Dom element = createElement( testCase, name );
-
- String stackTrace = elapsedForTest.getStackTrace( report );
-
- if ( report.getMessage() != null && report.getMessage().length() > 0 )
- {
- element.setAttribute( "message", report.getMessage() );
- }
-
- if ( report.getStackTraceWriter() != null )
- {
- //noinspection ThrowableResultOfMethodCallIgnored
- SafeThrowable t = report.getStackTraceWriter().getThrowable();
- if ( t != null )
- {
- if ( t.getMessage() != null )
- {
- element.setAttribute( "type", ( stackTrace.contains( ":" )
- ? stackTrace.substring( 0, stackTrace.indexOf( ":" ) )
- : stackTrace ) );
- }
- else
- {
- element.setAttribute( "type", new StringTokenizer( stackTrace ).nextToken() );
- }
- }
- }
-
- if ( stackTrace != null )
- {
- element.setValue( stackTrace );
- }
-
- addOutputStreamElement( stdOut, "system-out", testCase );
-
- addOutputStreamElement( stdErr, "system-err", testCase );
-
- results.add( testCase );
- }
-
- private void addOutputStreamElement( String stdOut, String name, Xpp3Dom testCase )
- {
- if ( stdOut != null && stdOut.trim().length() > 0 )
- {
- createElement( testCase, name ).setValue( stdOut );
- }
- }
-
- private Xpp3Dom createElement( Xpp3Dom element, String name )
- {
- Xpp3Dom component = new Xpp3Dom( name );
-
- element.addChild( component );
-
- return component;
- }
-
- /**
- * Adds system properties to the XML report.
- * <p/>
- *
- * @param testSuite The test suite to report to
- */
- private void showProperties( Xpp3Dom testSuite )
- {
- Xpp3Dom properties = createElement( testSuite, "properties" );
-
- Properties systemProperties = System.getProperties();
-
- if ( systemProperties != null )
- {
- Enumeration propertyKeys = systemProperties.propertyNames();
-
- while ( propertyKeys.hasMoreElements() )
- {
- String key = (String) propertyKeys.nextElement();
-
- String value = systemProperties.getProperty( key );
-
- if ( value == null )
- {
- value = "null";
- }
-
- Xpp3Dom property = createElement( properties, "property" );
-
- property.setAttribute( "name", key );
-
- property.setAttribute( "value", value );
-
- }
- }
- }
-
- public Iterator getResults()
- {
- return results.iterator();
- }
-
- public void reset()
- {
- results.clear();
- elapsed = 0;
- }
-}
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * 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 org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.SafeThrowable;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomWriter;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+/**
+ * XML format reporter writing to <code>TEST-<i>reportName</i>[-<i>suffix</i>].xml</code> file like written and read
+ * by Ant's <a href="http://ant.apache.org/manual/Tasks/junit.html"><code><junit></code></a> and
+ * <a href="http://ant.apache.org/manual/Tasks/junitreport.html"><code><junitreport></code></a> tasks,
+ * then supported by many tools like CI servers.
+ * <p/>
+ * <pre><?xml version="1.0" encoding="UTF-8"?>
+ * <testsuite name="<i>suite name</i>" [group="<i>group</i>"] tests="<i>0</i>" failures="<i>0</i>" errors="<i>0</i>" skipped="<i>0</i>" time="<i>0,###.###</i>">
+ * <properties>
+ * <property name="<i>name</i>" value="<i>value</i>"/>
+ * [...]
+ * </properties>
+ * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]"/>
+ * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
+ * <<b>error</b> message="<i>message</i>" type="<i>exception class name</i>"><i>stacktrace</i></error>
+ * <system-out><i>system out content (present only if not empty)</i></system-out>
+ * <system-err><i>system err content (present only if not empty)</i></system-err>
+ * </testcase>
+ * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
+ * <<b>failure</b> message="<i>message</i>" type="<i>exception class name</i>"><i>stacktrace</i></failure>
+ * <system-out><i>system out content (present only if not empty)</i></system-out>
+ * <system-err><i>system err content (present only if not empty)</i></system-err>
+ * </testcase>
+ * <testcase time="<i>0,###.###</i>" name="<i>test name</i> [classname="<i>class name</i>"] [group="<i>group</i>"]">
+ * <<b>skipped</b>/>
+ * </testcase>
+ * [...]</pre>
+ *
+ * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
+ * @author Kristian Rosenvold
+ * @see <a href="http://wiki.apache.org/ant/Proposals/EnhancedTestReports">Ant's format enhancement proposal</a>
+ * (not yet implemented by Ant 1.8.2)
+ */
+public class StatelessXmlReporter
+{
+ private static final String LS = System.getProperty( "line.separator" );
+
+ private final File reportsDirectory;
+
+ private final String reportNameSuffix;
+
+ private final boolean trimStackTrace;
+
+ public StatelessXmlReporter( File reportsDirectory, String reportNameSuffix, boolean trimStackTrace )
+ {
+ this.reportsDirectory = reportsDirectory;
+ this.reportNameSuffix = reportNameSuffix;
+ this.trimStackTrace = trimStackTrace;
+ }
+
+ public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStats testSetStats )
+ throws ReporterException
+ {
+
+ Xpp3Dom testSuite = createTestSuiteElement( testSetReportEntry, testSetStats, reportNameSuffix );
+
+ showProperties( testSuite );
+
+ testSuite.setAttribute( "tests", String.valueOf( testSetStats.getCompletedCount() ) );
+
+ testSuite.setAttribute( "errors", String.valueOf( testSetStats.getErrors() ) );
+
+ testSuite.setAttribute( "skipped", String.valueOf( testSetStats.getSkipped() ) );
+
+ testSuite.setAttribute( "failures", String.valueOf( testSetStats.getFailures() ) );
+
+ for ( WrappedReportEntry entry : testSetStats.getReportEntries() )
+ {
+ if ( ReportEntryType.success.equals( entry.getReportEntryType() ) )
+ {
+ testSuite.addChild( createTestElement( entry, reportNameSuffix ) );
+ }
+ else
+ {
+ testSuite.addChild( getTestProblems( entry, trimStackTrace, reportNameSuffix ) );
+ }
+
+ }
+
+ File reportFile = getReportFile( testSetReportEntry, reportsDirectory, reportNameSuffix );
+
+ File reportDir = reportFile.getParentFile();
+
+ //noinspection ResultOfMethodCallIgnored
+ reportDir.mkdirs();
+
+ PrintWriter writer = null;
+
+ try
+ {
+ writer = new PrintWriter(
+ new BufferedWriter( new OutputStreamWriter( new FileOutputStream( reportFile ), "UTF-8" ) ) );
+
+ writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + LS );
+
+ Xpp3DomWriter.write( new PrettyPrintXMLWriter( writer ), testSuite );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ throw new ReporterException( "Unable to use UTF-8 encoding", e );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new ReporterException( "Unable to create file: " + e.getMessage(), e );
+ }
+
+ finally
+ {
+ IOUtil.close( writer );
+ }
+ }
+
+ private File getReportFile( ReportEntry report, File reportsDirectory, String reportNameSuffix )
+ {
+ File reportFile;
+
+ if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
+ {
+ reportFile = new File( reportsDirectory, "TEST-" + report.getName() + "-" + reportNameSuffix + ".xml" );
+ }
+ else
+ {
+ reportFile = new File( reportsDirectory, "TEST-" + report.getName() + ".xml" );
+ }
+
+ return reportFile;
+ }
+
+ private static Xpp3Dom createTestElement( WrappedReportEntry report, String reportNameSuffix )
+ {
+ Xpp3Dom testCase = new Xpp3Dom( "testcase" );
+ testCase.setAttribute( "name", report.getReportName() );
+ if ( report.getGroup() != null )
+ {
+ testCase.setAttribute( "group", report.getGroup() );
+ }
+ if ( report.getSourceName() != null )
+ {
+ if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
+ {
+ testCase.setAttribute( "classname", report.getSourceName() + "(" + reportNameSuffix + ")" );
+ }
+ else
+ {
+ testCase.setAttribute( "classname", report.getSourceName() );
+ }
+ }
+ testCase.setAttribute( "time", report.elapsedTimeAsString() );
+ return testCase;
+ }
+
+ private static Xpp3Dom createTestSuiteElement( WrappedReportEntry report, TestSetStats testSetStats,
+ String reportNameSuffix1 )
+ {
+ Xpp3Dom testCase = new Xpp3Dom( "testsuite" );
+
+ testCase.setAttribute( "name", report.getReportName( reportNameSuffix1 ) );
+
+ if ( report.getGroup() != null )
+ {
+ testCase.setAttribute( "group", report.getGroup() );
+ }
+ testCase.setAttribute( "time", testSetStats.getElapsedForTestSet() );
+ return testCase;
+ }
+
+
+ private Xpp3Dom getTestProblems( WrappedReportEntry report, boolean trimStackTrace, String reportNameSuffix )
+ {
+
+ Xpp3Dom testCase = createTestElement( report, reportNameSuffix );
+
+ Xpp3Dom element = createElement( testCase, report.getReportEntryType().name() );
+
+ String stackTrace = report.getStackTrace( trimStackTrace );
+
+ if ( report.getMessage() != null && report.getMessage().length() > 0 )
+ {
+ element.setAttribute( "message", report.getMessage() );
+ }
+
+ if ( report.getStackTraceWriter() != null )
+ {
+ //noinspection ThrowableResultOfMethodCallIgnored
+ SafeThrowable t = report.getStackTraceWriter().getThrowable();
+ if ( t != null )
+ {
+ if ( t.getMessage() != null )
+ {
+ element.setAttribute( "type", ( stackTrace.contains( ":" )
+ ? stackTrace.substring( 0, stackTrace.indexOf( ":" ) )
+ : stackTrace ) );
+ }
+ else
+ {
+ element.setAttribute( "type", new StringTokenizer( stackTrace ).nextToken() );
+ }
+ }
+ }
+
+ if ( stackTrace != null )
+ {
+ element.setValue( stackTrace );
+ }
+
+ addOutputStreamElement( report.getStdout(), "system-out", testCase );
+
+ addOutputStreamElement( report.getStdErr(), "system-err", testCase );
+
+ return testCase;
+ }
+
+ private void addOutputStreamElement( String stdOut, String name, Xpp3Dom testCase )
+ {
+ if ( stdOut != null && stdOut.trim().length() > 0 )
+ {
+ createElement( testCase, name ).setValue( stdOut );
+ }
+ }
+
+ private Xpp3Dom createElement( Xpp3Dom element, String name )
+ {
+ Xpp3Dom component = new Xpp3Dom( name );
+
+ element.addChild( component );
+
+ return component;
+ }
+
+ /**
+ * Adds system properties to the XML report.
+ * <p/>
+ *
+ * @param testSuite The test suite to report to
+ */
+ private void showProperties( Xpp3Dom testSuite )
+ {
+ Xpp3Dom properties = createElement( testSuite, "properties" );
+
+ Properties systemProperties = System.getProperties();
+
+ if ( systemProperties != null )
+ {
+ Enumeration propertyKeys = systemProperties.propertyNames();
+
+ while ( propertyKeys.hasMoreElements() )
+ {
+ String key = (String) propertyKeys.nextElement();
+
+ String value = systemProperties.getProperty( key );
+
+ if ( value == null )
+ {
+ value = "null";
+ }
+
+ Xpp3Dom property = createElement( properties, "property" );
+
+ property.setAttribute( "name", key );
+
+ property.setAttribute( "value", value );
+
+ }
+ }
+ }
+}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java Fri Aug 17 13:53:40 2012
@@ -19,16 +19,23 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
+import org.apache.maven.surefire.report.ConsoleLogger;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.RunStatistics;
+import org.apache.maven.surefire.util.internal.ByteBuffer;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
-import org.apache.maven.surefire.report.*;
-import org.apache.maven.surefire.util.internal.ByteBuffer;
/**
* Reports data for a single test set.
* <p/>
+ *
+ * @author Kristian Rosenvold
*/
public class TestSetRunListener
implements RunListener, ConsoleOutputReceiver, ConsoleLogger
@@ -38,46 +45,44 @@ public class TestSetRunListener
private final TestSetStats detailsForThis;
- private final MulticastingReporter multicastingReporter;
-
private final List<ByteBuffer> testStdOut = Collections.synchronizedList( new ArrayList<ByteBuffer>() );
private final List<ByteBuffer> testStdErr = Collections.synchronizedList( new ArrayList<ByteBuffer>() );
private final TestcycleConsoleOutputReceiver consoleOutputReceiver;
- public TestSetRunListener( ConsoleReporter consoleReporter, FileReporter fileReporter, XMLReporter xmlReporter,
+ private final boolean briefOrPlainFormat;
+
+ private final StatelessXmlReporter simpleXMLReporter;
+
+ private final ConsoleReporter consoleReporter;
+
+ private final FileReporter fileReporter;
+
+ private final StatisticsReporter statisticsReporter;
+
+ public TestSetRunListener( ConsoleReporter consoleReporter, FileReporter fileReporter,
+ StatelessXmlReporter simpleXMLReporter,
TestcycleConsoleOutputReceiver consoleOutputReceiver,
StatisticsReporter statisticsReporter, RunStatistics globalStats, boolean trimStackTrace,
- boolean isPlainFormat )
+ boolean isPlainFormat, boolean briefOrPlainFormat )
{
- List<Reporter> reporters = new ArrayList<Reporter>();
- if ( consoleReporter != null )
- {
- reporters.add( consoleReporter );
- }
- if ( fileReporter != null )
- {
- reporters.add( fileReporter );
- }
- if ( xmlReporter != null )
- {
- reporters.add( xmlReporter );
- }
- if ( statisticsReporter != null )
- {
- reporters.add( statisticsReporter );
- }
-
+ this.consoleReporter = consoleReporter;
+ this.fileReporter = fileReporter;
+ this.statisticsReporter = statisticsReporter;
+ this.simpleXMLReporter = simpleXMLReporter;
this.consoleOutputReceiver = consoleOutputReceiver;
+ this.briefOrPlainFormat = briefOrPlainFormat;
this.detailsForThis = new TestSetStats( trimStackTrace, isPlainFormat );
- multicastingReporter = new MulticastingReporter( reporters );
this.globalStatistics = globalStats;
}
public void info( String message )
{
- multicastingReporter.writeMessage( message );
+ if ( consoleReporter != null )
+ {
+ consoleReporter.writeMessage( message );
+ }
}
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
@@ -97,7 +102,10 @@ public class TestSetRunListener
public void testSetStarting( ReportEntry report )
{
detailsForThis.testSetStart();
- multicastingReporter.testSetStarting( report );
+ if ( consoleReporter != null )
+ {
+ consoleReporter.testSetStarting( report );
+ }
consoleOutputReceiver.testSetStarting( report );
}
@@ -109,11 +117,33 @@ public class TestSetRunListener
public void testSetCompleted( ReportEntry report )
{
- multicastingReporter.testSetCompleted( report, detailsForThis );
- consoleOutputReceiver.testSetCompleted( report );
+ WrappedReportEntry wrap = wrapTestSet( report, null );
+ List<String> testResults = briefOrPlainFormat ? detailsForThis.getTestResults() : null;
+ if ( consoleReporter != null )
+ {
+ consoleReporter.testSetCompleted( wrap, detailsForThis, testResults );
+ }
+ consoleOutputReceiver.testSetCompleted( wrap );
+ if ( fileReporter != null )
+ {
+ fileReporter.testSetCompleted( wrap, detailsForThis, testResults );
+ }
+ if ( simpleXMLReporter != null )
+ {
+ simpleXMLReporter.testSetCompleted( wrap, detailsForThis );
+ }
+ if ( statisticsReporter != null )
+ {
+ statisticsReporter.testSetCompleted();
+ }
+ if ( consoleReporter != null )
+ {
+ consoleReporter.reset();
+ }
+
globalStatistics.add( detailsForThis );
detailsForThis.reset();
- multicastingReporter.reset();
+
}
// ----------------------------------------------------------------------
@@ -123,30 +153,40 @@ public class TestSetRunListener
public void testStarting( ReportEntry report )
{
detailsForThis.testStart();
- multicastingReporter.testStarting( report );
+
}
public void testSucceeded( ReportEntry reportEntry )
{
- detailsForThis.testEnd( reportEntry );
- multicastingReporter.testSucceeded( wrap( reportEntry ), detailsForThis );
+ WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.success );
+ detailsForThis.testSucceeded( wrapped );
+ if ( statisticsReporter != null )
+ {
+ statisticsReporter.testSucceeded( reportEntry );
+ }
clearCapture();
}
public void testError( ReportEntry reportEntry )
{
- detailsForThis.testError( reportEntry );
- multicastingReporter.testError( wrap( reportEntry ), getAsString( testStdOut ), getAsString( testStdErr ),
- detailsForThis );
+ WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.error );
+ detailsForThis.testError( wrapped );
+ if ( statisticsReporter != null )
+ {
+ statisticsReporter.testError( reportEntry );
+ }
globalStatistics.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter() );
clearCapture();
}
public void testFailed( ReportEntry reportEntry )
{
- detailsForThis.testFailure( reportEntry );
- multicastingReporter.testFailed( wrap( reportEntry ), getAsString( testStdOut ), getAsString( testStdErr ),
- detailsForThis );
+ WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.failure );
+ detailsForThis.testFailure( wrapped );
+ if ( statisticsReporter != null )
+ {
+ statisticsReporter.testFailed( reportEntry );
+ }
globalStatistics.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter() );
clearCapture();
}
@@ -158,9 +198,13 @@ public class TestSetRunListener
public void testSkipped( ReportEntry reportEntry )
{
- detailsForThis.testSkipped( reportEntry );
+ WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.skipped );
+ detailsForThis.testSkipped( wrapped );
+ if ( statisticsReporter != null )
+ {
+ statisticsReporter.testSkipped( reportEntry );
+ }
clearCapture();
- multicastingReporter.testSkipped( wrap( reportEntry ), detailsForThis );
}
public void testAssumptionFailure( ReportEntry report )
@@ -181,15 +225,18 @@ public class TestSetRunListener
return stringBuffer.toString();
}
- private ReportEntry wrap( ReportEntry other )
+ private WrappedReportEntry wrap( ReportEntry other, ReportEntryType reportEntryType )
{
- if ( other.getElapsed() != null )
- {
- return other;
- }
- return CategorizedReportEntry.reportEntry( other.getSourceName(), other.getName(), other.getGroup(),
- other.getStackTraceWriter(),
- detailsForThis.getElapsedSinceLastStart(), other.getMessage() );
+ return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null
+ ? other.getElapsed()
+ : detailsForThis.getElapsedSinceLastStart(), getAsString( testStdOut ), getAsString( testStdErr ) );
+ }
+
+ private WrappedReportEntry wrapTestSet( ReportEntry other, ReportEntryType reportEntryType )
+ {
+ return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null
+ ? other.getElapsed()
+ : detailsForThis.getElapsedSinceTestSetStart(), getAsString( testStdOut ), getAsString( testStdErr ) );
}
}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java Fri Aug 17 13:53:40 2012
@@ -18,9 +18,6 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.StackTraceWriter;
-
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
@@ -39,8 +36,6 @@ public class TestSetStats
private long testStartAt;
- private long testEndAt;
-
private int completedCount;
private int errors;
@@ -51,7 +46,9 @@ public class TestSetStats
private long lastStartAt;
- private final List<String> testResults = new ArrayList<String>();
+ private long elapsedForTestSet;
+
+ private final List<WrappedReportEntry> reportEntries = new ArrayList<WrappedReportEntry>();
public TestSetStats( boolean trimStackTrace, boolean plainFormat )
{
@@ -59,11 +56,6 @@ public class TestSetStats
this.plainFormat = plainFormat;
}
- public long getTestSetStartAt()
- {
- return testSetStartAt;
- }
-
public int getElapsedSinceTestSetStart()
{
return (int) ( System.currentTimeMillis() - testSetStartAt );
@@ -77,8 +69,6 @@ public class TestSetStats
public void testSetStart()
{
lastStartAt = testSetStartAt = System.currentTimeMillis();
- testResults.clear();
-
}
public void testStart()
@@ -86,58 +76,45 @@ public class TestSetStats
lastStartAt = testStartAt = System.currentTimeMillis();
}
- public long testEnd()
+ private long finishTest( WrappedReportEntry reportEntry )
{
+ reportEntries.add( reportEntry );
incrementCompletedCount();
- testEndAt = System.currentTimeMillis();
+ long testEndAt = System.currentTimeMillis();
// SUREFIRE-398 skipped tests call endTest without calling testStarting
// if startTime = 0, set it to endTime, so the diff will be 0
if ( testStartAt == 0 )
{
testStartAt = testEndAt;
}
- return testEndAt - testStartAt;
+ long elapsedForThis = reportEntry.getElapsed() != null ? reportEntry.getElapsed() : testEndAt - testStartAt;
+ elapsedForTestSet += elapsedForThis;
+ return elapsedForThis;
}
- public void testEnd( ReportEntry reportEntry )
+ public void testSucceeded( WrappedReportEntry reportEntry )
{
- testEnd();
- if ( plainFormat )
- {
- addTestResult( reportEntry );
- }
+ finishTest( reportEntry );
}
- public void incrementCompletedCount()
- {
- completedCount += 1;
- }
-
- public void testError( ReportEntry reportEntry )
+ public void testError( WrappedReportEntry reportEntry )
{
errors += 1;
- testEnd();
- testResults.add( getOutput( reportEntry, "ERROR" ) );
+ finishTest( reportEntry );
}
- public void testFailure( ReportEntry reportEntry )
+ public void testFailure( WrappedReportEntry reportEntry )
{
failures += 1;
- testEnd();
- testResults.add( getOutput( reportEntry, "FAILURE" ) );
+ finishTest( reportEntry );
}
- public void testSkipped( ReportEntry reportEntry )
+ public void testSkipped( WrappedReportEntry reportEntry )
{
skipped += 1;
- testEnd();
- if ( plainFormat )
- {
- testResults.add( reportEntry.getName() + " skipped" );
- }
-
+ finishTest( reportEntry );
}
public void reset()
@@ -146,6 +123,8 @@ public class TestSetStats
errors = 0;
failures = 0;
skipped = 0;
+ elapsedForTestSet = 0;
+ reportEntries.clear();
}
public int getCompletedCount()
@@ -168,28 +147,28 @@ public class TestSetStats
return skipped;
}
- long getActualRunTime( ReportEntry reportEntry )
- {
- @SuppressWarnings( "deprecation" )
- final Integer clientSpecifiedElapsed = reportEntry.getElapsed();
- return clientSpecifiedElapsed != null ? clientSpecifiedElapsed : testEndAt - testStartAt;
- }
-
private static final String TEST_SET_COMPLETED_PREFIX = "Tests run: ";
private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
- static final String NL = System.getProperty( "line.separator" );
-
private static final int MS_PER_SEC = 1000;
-
String elapsedTimeAsString( long runTime )
{
return numberFormat.format( (double) runTime / MS_PER_SEC );
}
- public String getTestSetSummary( Integer elapsed )
+ public String getElapsedForTestSet()
+ {
+ return elapsedTimeAsString( elapsedForTestSet );
+ }
+
+ private void incrementCompletedCount()
+ {
+ completedCount += 1;
+ }
+
+ public String getTestSetSummary( WrappedReportEntry reportEntry )
{
StringBuilder buf = new StringBuilder();
@@ -202,7 +181,7 @@ public class TestSetStats
buf.append( ", Skipped: " );
buf.append( skipped );
buf.append( ", Time elapsed: " );
- buf.append( elapsedTimeAsString( elapsed != null ? elapsed : getElapsedSinceTestSetStart() ) );
+ buf.append( reportEntry.elapsedTimeAsString() );
buf.append( " sec" );
if ( failures > 0 || errors > 0 )
@@ -215,54 +194,29 @@ public class TestSetStats
return buf.toString();
}
- public String getElapsedTimeSummary( ReportEntry report )
- {
- StringBuilder reportContent = new StringBuilder();
- reportContent.append( report.getName() );
- reportContent.append( " Time elapsed: " );
- reportContent.append( getActualRunTime( report ) );
- reportContent.append( " sec" );
-
- return reportContent.toString();
- }
-
-
- public String getOutput( ReportEntry report, String msg )
- {
- StringBuilder buf = new StringBuilder();
-
- buf.append( getElapsedTimeSummary( report ) );
-
- buf.append( " <<< " ).append( msg ).append( "!" ).append( NL );
-
- buf.append( getStackTrace( report ) );
-
- return buf.toString();
- }
-
- /**
- * Returns stacktrace as String.
- *
- * @param report ReportEntry object.
- * @return stacktrace as string.
- */
- public String getStackTrace( ReportEntry report )
+ public List<String> getTestResults()
{
- StackTraceWriter writer = report.getStackTraceWriter();
- if ( writer == null )
+ List<String> result = new ArrayList<String>();
+ for ( WrappedReportEntry testResult : reportEntries )
{
- return null;
+ if ( testResult.isErrorOrFailure() )
+ {
+ result.add( testResult.getOutput( trimStackTrace ) );
+ }
+ else if ( plainFormat && testResult.isSkipped() )
+ {
+ result.add( testResult.getName() + " skipped" );
+ }
+ else if ( plainFormat && testResult.isSucceeded() )
+ {
+ result.add( testResult.getElapsedTimeSummary() );
+ }
}
- return this.trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
+ return result;
}
- public void addTestResult( ReportEntry reportEntry )
- {
- testResults.add( getElapsedTimeSummary( reportEntry ) );
- }
-
- public List<String> getTestResults()
+ public List<WrappedReportEntry> getReportEntries()
{
- return testResults;
+ return reportEntries;
}
}
Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java?rev=1374259&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java Fri Aug 17 13:53:40 2012
@@ -0,0 +1,168 @@
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * 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.text.NumberFormat;
+import java.util.Locale;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class WrappedReportEntry implements ReportEntry
+{
+ private final ReportEntry original;
+ private final ReportEntryType reportEntryType;
+
+ private final Integer elapsed;
+
+ private final String stdout;
+ private final String stdErr;
+
+ private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
+
+ private static final int MS_PER_SEC = 1000;
+
+ static final String NL = System.getProperty( "line.separator" );
+
+ public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed, String stdout, String stdErr )
+ {
+ this.original = original;
+ this.reportEntryType = reportEntryType;
+ this.elapsed = estimatedElapsed;
+ this.stdout = stdout;
+ this.stdErr = stdErr;
+ }
+
+ public Integer getElapsed()
+ {
+ return original.getElapsed() != null ? original.getElapsed() : elapsed;
+ }
+
+
+ public ReportEntryType getReportEntryType()
+ {
+ return reportEntryType;
+ }
+
+ public String getStdout()
+ {
+ return stdout;
+ }
+
+ public String getStdErr()
+ {
+ return stdErr;
+ }
+
+ public String getSourceName()
+ {
+ return original.getSourceName();
+ }
+
+ public String getName()
+ {
+ return original.getName();
+ }
+
+ public String getGroup()
+ {
+ return original.getGroup();
+ }
+
+ public StackTraceWriter getStackTraceWriter()
+ {
+ return original.getStackTraceWriter();
+ }
+
+ public String getMessage()
+ {
+ return original.getMessage();
+ }
+
+ public String getStackTrace( boolean trimStackTrace )
+ {
+ StackTraceWriter writer = original.getStackTraceWriter();
+ if ( writer == null )
+ {
+ return null;
+ }
+ return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
+ }
+
+ public String elapsedTimeAsString()
+ {
+ return elapsedTimeAsString(getElapsed());
+ }
+
+ String elapsedTimeAsString( long runTime )
+ {
+ return numberFormat.format( (double) runTime / MS_PER_SEC );
+ }
+
+ public String getReportName( )
+ {
+ final int i = getName().lastIndexOf( "(" );
+ return i > 0 ? getName().substring( 0, i ) : getName();
+ }
+
+ public String getReportName( String suffix)
+ {
+ return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName();
+ }
+
+ public String getOutput(boolean trimStackTrace)
+ {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append( getElapsedTimeSummary( ) );
+
+ buf.append( " <<< " ).append( getReportEntryType().toString().toUpperCase()).append("!").append( NL );
+
+ buf.append( getStackTrace(trimStackTrace) );
+
+ return buf.toString();
+ }
+
+ public String getElapsedTimeSummary( )
+ {
+ StringBuilder reportContent = new StringBuilder();
+ reportContent.append( getName() );
+ reportContent.append( " Time elapsed: " );
+ reportContent.append( getElapsed() );
+ reportContent.append( " sec" );
+
+ return reportContent.toString();
+ }
+
+ public boolean isErrorOrFailure() {
+ ReportEntryType thisType = getReportEntryType();
+ return ReportEntryType.failure == thisType || ReportEntryType.error == thisType;
+ }
+
+ public boolean isSkipped() {
+ return ReportEntryType.skipped == getReportEntryType();
+ }
+
+ public boolean isSucceeded() {
+ return ReportEntryType.success == getReportEntryType();
+ }
+}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java Fri Aug 17 13:53:40 2012
@@ -19,18 +19,16 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-import java.io.File;
-import java.io.FileNotFoundException;
-import org.apache.maven.plugin.surefire.report.Reporter;
-import org.apache.maven.plugin.surefire.report.TestSetStats;
import org.apache.maven.surefire.report.ReportEntry;
import org.apache.maven.surefire.util.NestedRuntimeException;
+import java.io.File;
+import java.io.FileNotFoundException;
+
/**
* @author Kristian Rosenvold
*/
public class StatisticsReporter
- implements Reporter
{
private final RunEntryStatisticsMap existing;
@@ -45,11 +43,7 @@ public class StatisticsReporter
this.newResults = new RunEntryStatisticsMap();
}
- public void testSetStarting( ReportEntry report )
- {
- }
-
- public void testSetCompleted( ReportEntry report, TestSetStats testSetStats )
+ public void testSetCompleted()
{
try
{
@@ -61,35 +55,23 @@ public class StatisticsReporter
}
}
- public void testStarting( ReportEntry report )
- {
- }
-
- public void testSucceeded( ReportEntry report, TestSetStats testSetStats )
+ public void testSucceeded( ReportEntry report )
{
newResults.add( existing.createNextGeneration( report ) );
}
- public void testSkipped( ReportEntry report, TestSetStats testSetStats )
+ public void testSkipped( ReportEntry report )
{
newResults.add( existing.createNextGeneration( report ) );
}
- public void testError( ReportEntry report, String stdOut, String stdErr, TestSetStats testSetStats )
+ public void testError( ReportEntry report )
{
newResults.add( existing.createNextGenerationFailure( report ) );
}
- public void testFailed( ReportEntry report, String stdOut, String stdErr, TestSetStats testSetStats )
+ public void testFailed( ReportEntry report )
{
newResults.add( existing.createNextGenerationFailure( report ) );
}
-
- public void writeMessage( String message )
- {
- }
-
- public void reset()
- {
- }
}
Added: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java?rev=1374259&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java Fri Aug 17 13:53:40 2012
@@ -0,0 +1,70 @@
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * 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.File;
+
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+public class StatelessXMLReporterTest
+ extends TestCase
+{
+
+ private StatelessXmlReporter reporter = new StatelessXmlReporter( new File( "." ), null, false );
+
+ private ReportEntry reportEntry;
+
+ private String message;
+
+ private TestSetStats stats;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ message = "junit.framework.AssertionFailedError";
+ reportEntry = new SimpleReportEntry( this.getClass().getName(), "StatelessXMLReporterTest",
+ new PojoStackTraceWriter( "", "", new AssertionFailedError() ), 17 );
+ stats = new TestSetStats( false, true );
+ }
+
+ public void testFileNameWithoutSuffix()
+ {
+ File reportDir = new File( "." );
+ String testName = "org.apache.maven.plugin.surefire.report.StatelessXMLReporterTest";
+ reportEntry = new SimpleReportEntry( this.getClass().getName(), testName, 12 );
+ WrappedReportEntry testSetReportEntry = new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
+ stats.testSucceeded( testSetReportEntry );
+ reporter.testSetCompleted( testSetReportEntry, stats );
+
+ File expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
+ assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
+ expectedReportFile.exists() );
+ //noinspection ResultOfMethodCallIgnored
+ expectedReportFile.delete();
+ }
+
+}
Added: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java?rev=1374259&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java Fri Aug 17 13:53:40 2012
@@ -0,0 +1,43 @@
+package org.apache.maven.plugin.surefire.report;
+
+import junit.framework.TestCase;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class WrappedReportEntryTest
+ extends TestCase
+{
+
+ public void testClassNameOnly()
+ throws Exception
+ {
+ String category = "surefire.testcase.JunitParamsTest";
+ WrappedReportEntry wr =
+ new WrappedReportEntry( new SimpleReportEntry( "fud", category ), null, 12, null, null );
+ final String reportName = wr.getReportName();
+ assertEquals( "surefire.testcase.JunitParamsTest", reportName );
+ }
+
+ public void testRegular()
+ {
+ ReportEntry reportEntry = new SimpleReportEntry( "fud", "testSum(surefire.testcase.NonJunitParamsTest)" );
+ WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null );
+ final String reportName = wr.getReportName();
+ assertEquals( "testSum", reportName );
+ }
+
+ public void testGetReportNameWithParams()
+ throws Exception
+ {
+ String category = "[0] 1\u002C 2\u002C 3 (testSum)(surefire.testcase.JunitParamsTest)";
+ ReportEntry reportEntry = new SimpleReportEntry( "fud", category );
+ WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null );
+ final String reportName = wr.getReportName();
+ assertEquals( "[0] 1, 2, 3 (testSum)", reportName );
+ }
+
+
+}
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/ConsoleOutputFileReporterTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/ConsoleOutputFileReporterTest.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/ConsoleOutputFileReporterTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/ConsoleOutputFileReporterTest.java Fri Aug 17 13:53:40 2012
@@ -19,10 +19,10 @@ package org.apache.maven.surefire.report
* under the License.
*/
-import java.io.File;
+import junit.framework.TestCase;
import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
-import junit.framework.TestCase;
+import java.io.File;
public class ConsoleOutputFileReporterTest
extends TestCase
@@ -43,7 +43,7 @@ public class ConsoleOutputFileReporterTe
reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
reporter = new ConsoleOutputFileReporter( reportDir, null );
reporter.testSetStarting( reportEntry );
- reporter.writeMessage( "some text".getBytes(), 0, 5 );
+ reporter.writeTestOutput( "some text".getBytes(), 0, 5, true );
reporter.testSetCompleted( reportEntry );
File expectedReportFile = new File( reportDir, testName + "-output.txt" );
@@ -62,7 +62,7 @@ public class ConsoleOutputFileReporterTe
reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
reporter = new ConsoleOutputFileReporter( reportDir, suffixText );
reporter.testSetStarting( reportEntry );
- reporter.writeMessage( "some text".getBytes(), 0, 5 );
+ reporter.writeTestOutput( "some text".getBytes(), 0, 5, true );
reporter.testSetCompleted( reportEntry );
File expectedReportFile = new File( reportDir, testName + "-" + suffixText + "-output.txt" );
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java?rev=1374259&r1=1374258&r2=1374259&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java Fri Aug 17 13:53:40 2012
@@ -20,19 +20,19 @@ package org.apache.maven.surefire.report
*/
import junit.framework.TestCase;
-
import org.apache.maven.plugin.surefire.report.FileReporter;
-import org.apache.maven.plugin.surefire.report.Reporter;
+import org.apache.maven.plugin.surefire.report.ReportEntryType;
+import org.apache.maven.plugin.surefire.report.TestSetStats;
+import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
import java.io.File;
-
-import static org.apache.maven.plugin.surefire.report.AbstractTextReporter.PLAIN;
+import java.util.ArrayList;
public class FileReporterTest
extends TestCase
{
- private Reporter reporter;
+ private FileReporter reporter;
private ReportEntry reportEntry;
@@ -42,8 +42,10 @@ public class FileReporterTest
{
File reportDir = new File( "target" );
reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
- reporter = new FileReporter( PLAIN, reportDir, null );
- reporter.testSetStarting( reportEntry );
+ WrappedReportEntry wrappedReportEntry =
+ new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
+ reporter = new FileReporter( reportDir, null );
+ reporter.testSetCompleted( wrappedReportEntry, createTestSetStats(), new ArrayList<String>() );
File expectedReportFile = new File( reportDir, testName + ".txt" );
assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
@@ -51,13 +53,20 @@ public class FileReporterTest
expectedReportFile.delete();
}
+ private TestSetStats createTestSetStats()
+ {
+ return new TestSetStats( true, true );
+ }
+
public void testFileNameWithSuffix()
{
File reportDir = new File( "target" );
String suffixText = "sampleSuffixText";
reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
- reporter = new FileReporter( PLAIN, reportDir, suffixText );
- reporter.testSetStarting( reportEntry );
+ WrappedReportEntry wrappedReportEntry =
+ new WrappedReportEntry( reportEntry, ReportEntryType.success, 12, null, null );
+ reporter = new FileReporter( reportDir, suffixText );
+ reporter.testSetCompleted( wrappedReportEntry, createTestSetStats(), new ArrayList<String>() );
File expectedReportFile = new File( reportDir, testName + "-" + suffixText + ".txt" );
assertTrue( "Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/pom.xml?rev=1374259&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/small-result-counting/pom.xml Fri Aug 17 13:53:40 2012
@@ -0,0 +1,44 @@
+<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>maven-surefire</groupId>
+ <artifactId>small-result-counting</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>small-result-counting</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <configuration>
+ <forkMode>${forkMode}</forkMode>
+ <includes>
+ <include>**/Test*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <junit.version>4.8.1</junit.version>
+ <forkMode>once</forkMode>
+ </properties>
+</project>