maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1057904 - in /maven/surefire/trunk: surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ surefire-api/src/test/java/org/apache/maven/surefire/report/ surefire-inte...
Date Tue, 11 Jan 2011 22:45:47 GMT
Author: krosenvold
Date: Tue Jan 11 22:45:46 2011
New Revision: 1057904

URL: http://svn.apache.org/viewvc?rev=1057904&view=rev
Log:
[SUREFIRE-645] Meaningful message when test has no runnable methods

Patch submitted by Stefan Birkner, applied with modifications. Added integration test

Added:
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java
  (with props)
Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/RunStatistics.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
    maven/surefire/trunk/surefire-providers/common-junit3/src/test/java/org/apache/maven/surefire/common/junit3/JUnit3TestCheckerTest.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java?rev=1057904&r1=1057903&r2=1057904&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
Tue Jan 11 22:45:46 2011
@@ -145,7 +145,7 @@ public class ReporterManager
         multicastingReporter.testError( reportEntry, stdOutLog, stdErrLog );
         runStatisticsForThis.incrementErrorsCount();
         runStatisticsForThis.incrementCompletedCount();
-        runStatisticsForThis.addErrorSource( reportEntry.getName() );
+        runStatisticsForThis.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter()
);
         consoleCapturer.clearCapturedContent();
     }
 
@@ -154,13 +154,12 @@ public class ReporterManager
         testFailed( reportEntry, consoleCapturer.getStdOutLog(), consoleCapturer.getStdErrLog()
);
     }
 
-
     public void testFailed( ReportEntry reportEntry, String stdOutLog, String stdErrLog )
     {
         multicastingReporter.testFailed( reportEntry, stdOutLog, stdErrLog );
         runStatisticsForThis.incrementFailureCount();
         runStatisticsForThis.incrementCompletedCount();
-        runStatisticsForThis.addFailureSource( reportEntry.getName() );
+        runStatisticsForThis.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter()
);
         consoleCapturer.clearCapturedContent();
     }
 

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/RunStatistics.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/RunStatistics.java?rev=1057904&r1=1057903&r2=1057904&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/RunStatistics.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/RunStatistics.java
Tue Jan 11 22:45:46 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
+import org.apache.maven.surefire.util.internal.StringUtils;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -32,46 +34,82 @@ public class RunStatistics
     /**
      * Holds the source(s) that causes the error(s).
      */
-    private final Collection errorSources = new ArrayList();
+    private final Sources errorSources = new Sources();
 
     /**
      * Holds the source(s) that causes the failure(s).
      */
-    private final Collection failureSources = new ArrayList();
+    private final Sources failureSources = new Sources();
 
 
+    // Todo remove when building with 2.7.2
     public void addErrorSource( String errorSource )
     {
-        synchronized ( errorSources )
-        {
-            errorSources.add( errorSource );
-        }
+        errorSources.addSource( errorSource );
     }
 
-    public void addFailureSource( String errorSource )
+    public void addErrorSource( String errorSource, StackTraceWriter stackTraceWriter )
     {
-        synchronized ( failureSources )
-        {
-            failureSources.add( errorSource );
-        }
+        errorSources.addSource( errorSource, stackTraceWriter );
     }
 
+    // Todo remove when building with 2.7.2
+    public void addFailureSource( String failureSource )
+    {
+    	failureSources.addSource( failureSource );
+    }
 
-    public Collection getFailureSources()
+    public void addFailureSource( String failureSource, StackTraceWriter stackTraceWriter
 )
     {
-        synchronized ( failureSources )
-        {
-            return Collections.unmodifiableCollection( failureSources );
-        }
+    	failureSources.addSource( failureSource, stackTraceWriter );
     }
 
     public Collection getErrorSources()
     {
-        synchronized ( errorSources )
+        return errorSources.getListOfSources();
+    }
+
+    public Collection getFailureSources()
+    {
+        return failureSources.getListOfSources();
+    }
+
+    private static class Sources
+    {
+        private final Collection listOfSources = new ArrayList();
+
+        void addSource( String source )
         {
-            return Collections.unmodifiableCollection( errorSources );
+            synchronized ( listOfSources )
+            {
+                listOfSources.add( source );  		
+            }
         }
-    }
 
+        void addSource( String source, StackTraceWriter stackTraceWriter )
+        {
+            String message = getMessageOfThrowable( stackTraceWriter );
+            String extendedSource = StringUtils.isBlank( message ) ? source : source + ":
" + message;
+            addSource( extendedSource );
+        }
 
+        Collection getListOfSources()
+        {
+            synchronized ( listOfSources )
+            {
+                return Collections.unmodifiableCollection( listOfSources );
+            }
+        }
+
+        private String getMessageOfThrowable( StackTraceWriter stackTraceWriter )
+        {
+            //noinspection ThrowableResultOfMethodCallIgnored
+            return stackTraceWriter != null ? getMessageOfThrowable( stackTraceWriter.getThrowable()
) : "";
+        }
+
+        private String getMessageOfThrowable( Throwable throwable )
+        {
+            return throwable != null ? throwable.getLocalizedMessage() : "";
+        }
+    }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java?rev=1057904&r1=1057903&r2=1057904&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
Tue Jan 11 22:45:46 2011
@@ -139,5 +139,17 @@ public class StringUtils
         return buf.toString();
     }
 
+
+    /**
+     * <p>Checks if a (trimmed) String is <code>null</code> or blank.</p>
+     *
+     * @param str the String to check
+     * @return <code>true</code> if the String is <code>null</code>,
or
+     *  length zero once trimmed
+     */
+    public static boolean isBlank( String str )
+    {
+        return ( ( str == null ) || ( str.trim().length() == 0 ) );
+    }
 }
 

Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java?rev=1057904&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java
(added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java
Tue Jan 11 22:45:46 2011
@@ -0,0 +1,119 @@
+package org.apache.maven.surefire.report;
+
+import java.util.Collection;
+import junit.framework.TestCase;
+
+/*
+ * Copyright 2002-2009 the original author or authors.
+ *
+ * Licensed 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 class RunStatisticsTest
+    extends TestCase
+{
+    private static final String DUMMY_ERROR_SOURCE = "dummy error source";
+
+    private static final String DUMMY_FAILURE_SOURCE = "dummy failure source";
+
+    private static final String DUMMY_MESSAGE = "dummy message";
+
+    public void testAddErrorSourceWithThrowableMessage()
+    {
+        RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
+        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable
);
+        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE + ": " + DUMMY_MESSAGE
);
+    }
+
+    public void testAddErrorSourceWithoutStackTraceWriter()
+    {
+        RunStatistics statistics = new RunStatistics();
+        statistics.addErrorSource( DUMMY_ERROR_SOURCE, null );
+        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
+    }
+
+    public void testAddErrorSourceWithoutThrowable()
+    {
+        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( null
);
+        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
+    }
+
+    public void testAddErrorSourceWithThrowableWithoutMessage()
+    {
+        RuntimeException throwable = new RuntimeException();
+        RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable
);
+        assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE );
+    }
+
+    public void testAddFailureSourceWithThrowableMessage()
+    {
+        RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE );
+        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable
);
+        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE + ": " + DUMMY_MESSAGE
);
+    }
+
+    public void testAddFailureSourceWithoutStackTraceWriter()
+    {
+        RunStatistics statistics = new RunStatistics();
+        statistics.addFailureSource( DUMMY_FAILURE_SOURCE, null );
+        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
+    }
+
+    public void testAddFailureSourceWithoutThrowable()
+    {
+        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( null
);
+        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
+    }
+
+    public void testAddFailureSourceWithThrowableWithoutMessage()
+    {
+        RuntimeException throwable = new RuntimeException();
+        RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable
);
+        assertRunStatisticsHasFailureSource( statistics, DUMMY_FAILURE_SOURCE );
+    }
+
+    private RunStatistics createRunStatisticsAndAddErrorSourceWithThrowable( Throwable throwable
)
+    {
+        StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable
);
+        RunStatistics statistics = new RunStatistics();
+        statistics.addErrorSource( DUMMY_ERROR_SOURCE, stackTraceWriter );
+
+        return statistics;
+    }
+
+    private RunStatistics createRunStatisticsAndAddFailureSourceWithThrowable( Throwable
throwable )
+    {
+        StackTraceWriter stackTraceWriter = new PojoStackTraceWriter( null, null, throwable
);
+        RunStatistics statistics = new RunStatistics();
+        statistics.addFailureSource( DUMMY_FAILURE_SOURCE, stackTraceWriter );
+
+        return statistics;
+    }
+
+    private void assertRunStatisticsHasErrorSource( RunStatistics statistics, String expectedErrorSource
)
+    {
+        Collection errorSources = statistics.getErrorSources();
+        assertNotNull( "No error sources.", errorSources );
+        assertEquals( "Wrong number of error sources.", 1, errorSources.size() );
+        assertEquals( "Wrong error sources.", expectedErrorSource, errorSources.iterator().next()
);
+    }
+
+    private void assertRunStatisticsHasFailureSource( RunStatistics statistics, String expectedFailureSource
)
+    {
+        Collection failureSources = statistics.getFailureSources();
+        assertNotNull( "No failure sources.", failureSources );
+        assertEquals( "Wrong number of failure sources.", 1, failureSources.size() );
+        assertEquals( "Wrong failure sources.", expectedFailureSource, failureSources.iterator().next()
);
+    }
+}

Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java?rev=1057904&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java
Tue Jan 11 22:45:46 2011
@@ -0,0 +1,43 @@
+package org.apache.maven.surefire.its;
+/*
+ * 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.
+ */
+
+
+/**
+ * SUREFIRE-621 Asserts proper test counts when running junit 3 tests in parallel
+ *
+ * @author Kristian Rosenvold
+ */
+public class NoRunnableTestsInClassIT
+    extends SurefireVerifierTestClass
+{
+
+    public NoRunnableTestsInClassIT()
+    {
+        super( "/norunnableTests" );
+    }
+
+    public void testJunit3ParallelBuildResultCount()
+        throws Exception
+    {
+        failNever();
+        execute( "test" );
+        verifyTextInLog( "No tests found in junit.norunnabletests.BasicTest" );
+    }
+}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/NoRunnableTestsInClassIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml?rev=1057904&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml
Tue Jan 11 22:45:46 2011
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>norunnabletests</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test JUnit classes with inner classes</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+        <configuration>
+          <failIfNoTests>true</failIfNoTests>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java?rev=1057904&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java
Tue Jan 11 22:45:46 2011
@@ -0,0 +1,8 @@
+package junit.norunnabletests;
+
+import junit.framework.TestCase;
+
+
+public class BasicTest extends TestCase
+{
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/norunnableTests/src/test/java/junit/norunnabletests/BasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-providers/common-junit3/src/test/java/org/apache/maven/surefire/common/junit3/JUnit3TestCheckerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/common-junit3/src/test/java/org/apache/maven/surefire/common/junit3/JUnit3TestCheckerTest.java?rev=1057904&r1=1057903&r2=1057904&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/common-junit3/src/test/java/org/apache/maven/surefire/common/junit3/JUnit3TestCheckerTest.java
(original)
+++ maven/surefire/trunk/surefire-providers/common-junit3/src/test/java/org/apache/maven/surefire/common/junit3/JUnit3TestCheckerTest.java
Tue Jan 11 22:45:46 2011
@@ -1,5 +1,24 @@
 package org.apache.maven.surefire.common.junit3;
 
+/*
+ * 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 junit.framework.TestCase;
 import junit.framework.TestResult;
 import org.apache.maven.surefire.testset.TestSetFailedException;



Mime
View raw message