incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1489749 - in /sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing: LoggingSuite.java TestAll.java
Date Wed, 05 Jun 2013 08:59:13 GMT
Author: bdelacretaz
Date: Wed Jun  5 08:59:13 2013
New Revision: 1489749

URL: http://svn.apache.org/r1489749
Log:
SLING-2903 - use JUnit4TestAdapter to accept JUnit4 style tests as well

Modified:
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/TestAll.java

Modified: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java?rev=1489749&r1=1489748&r2=1489749&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
(original)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
Wed Jun  5 08:59:13 2013
@@ -16,10 +16,7 @@
  */
 package org.apache.sling.launchpad.testing;
 
-import java.util.Set;
-
 import junit.framework.Test;
-import junit.framework.TestCase;
 import junit.framework.TestResult;
 import junit.framework.TestSuite;
 
@@ -38,8 +35,8 @@ class LoggingSuite extends TestSuite {
 
     private int lastFailures;
 
-    LoggingSuite(Set<Class<TestCase>> classSet, String name, Logger logger) {
-        super(classSet.toArray(new Class[classSet.size()]), name);
+    LoggingSuite(String name, Logger logger) {
+        super(name);
         this.logger = logger;
     }
 
@@ -51,9 +48,7 @@ class LoggingSuite extends TestSuite {
 
     @Override
     public void runTest(Test test, TestResult result) {
-        final String name = (test instanceof TestSuite)
-                ? ((TestSuite) test).getName()
-                : test.getClass().getName();
+        final String name = getName(test); 
         final String startMessage = String.format("Running %s", name);
         System.out.println(startMessage);
         logger.info(startMessage);
@@ -72,5 +67,9 @@ class LoggingSuite extends TestSuite {
         lastFailures = result.failureCount();
         lastErrors = result.errorCount();
     }
+    
+    private String getName(Test t) {
+        return (t instanceof TestSuite) ? ((TestSuite) t).getName() : t.toString();
+    }
 
 }

Modified: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/TestAll.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/TestAll.java?rev=1489749&r1=1489748&r2=1489749&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/TestAll.java
(original)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/testing/TestAll.java
Wed Jun  5 08:59:13 2013
@@ -16,13 +16,6 @@
  */
 package org.apache.sling.launchpad.testing;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Modifier;
@@ -31,21 +24,28 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.regex.Pattern;
 
-/**
- *
- */
-public class TestAll extends TestCase {
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import static org.junit.Assert.fail;
+import org.junit.runner.RunWith;
+import org.junit.runners.AllTests;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Collect our tests and run them with our LoggingSuite */
+ @RunWith(AllTests.class)
+public class TestAll {
     private static final Logger LOGGER = LoggerFactory.getLogger(TestAll.class);
 
     @SuppressWarnings("unchecked")
-    public static Test suite() {
+    public static TestSuite suite() {
         final ClassLoader sysClassLoader = TestAll.class.getClassLoader();
         final List<String> matchingClasses = new ArrayList<String>();
         // Get the URLs
@@ -63,24 +63,27 @@ public class TestAll extends TestCase {
                 e.printStackTrace();
             }
         }
-        final Set<Class<TestCase>> classSet = new HashSet<Class<TestCase>>();
+        
+        final TestSuite suite = new LoggingSuite("Sling Integration Tests matching " + testPattern,
LOGGER);
+        int counter=0;
         for (String classFile : matchingClasses) {
             String className = classFileToName(classFile);
             try {
                 final Class<TestCase> c = (Class<TestCase>) sysClassLoader.loadClass(className);
                 if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) {
+                    suite.addTest(new JUnit4TestAdapter(c));
+                    counter++;
                     LOGGER.info("Added " + className);
-                    classSet.add(c);
                 }
             } catch (ClassNotFoundException e) {
                 e.printStackTrace();
             }
         }
-        LOGGER.info(classSet.size() + " test classes found using Pattern "
-            + testRegex);
-        TestSuite suite = new LoggingSuite(classSet,
-            "Sling Integration Tests matching " + testPattern, LOGGER);
-
+        
+        if(counter==0) {
+            fail("No test classes found in classpath using Pattern " + testRegex);
+        }
+        LOGGER.info("{} test classes found using Pattern {}", counter, testRegex);
         return suite;
     }
 



Mime
View raw message