You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/02/01 21:21:30 UTC

svn commit: r1727996 - /jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java

Author: pmouawad
Date: Mon Feb  1 20:21:30 2016
New Revision: 1727996

URL: http://svn.apache.org/viewvc?rev=1727996&view=rev
Log:
Bug 58897 : Improve JUnit Test code
Part 3
#resolve #95
Bugzilla Id: 58897

Modified:
    jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java

Modified: jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java?rev=1727996&r1=1727995&r2=1727996&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java (original)
+++ jmeter/trunk/test/src/org/apache/jorphan/test/AllTests.java Mon Feb  1 20:21:30 2016
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.nio.charset.Charset;
@@ -135,7 +136,8 @@ public final class AllTests {
             System.out.println("You must specify a comma-delimited list of paths to search " + "for unit tests");
             return;
         }
-        String home=new File(System.getProperty("user.dir")).getParent();
+        
+        String home = new File(System.getProperty("user.dir")).getParent();
         System.out.println("Setting JMeterHome: "+home);
         JMeterUtils.setJMeterHome(home);
         initializeLogging(args);
@@ -166,9 +168,9 @@ public final class AllTests {
         logprop("os.version", true);
         logprop("os.arch");
         logprop("java.class.version");
-        // logprop("java.class.path");
+        
         String cp = System.getProperty("java.class.path");
-        String cpe[] = JOrphanUtils.split(cp, java.io.File.pathSeparator);
+        String[] cpe = JOrphanUtils.split(cp, java.io.File.pathSeparator);
         StringBuilder sb = new StringBuilder(3000);
         sb.append("java.class.path=");
         for (String path : cpe) {
@@ -188,7 +190,7 @@ public final class AllTests {
         
         System.out.println("------------");
         try {
-            System.out.println("Searching junit tests in:"+args[0]);
+            System.out.println("Searching junit tests in : "+args[0]);
             List<String> tests = findJMeterJUnitTests(args[0]);
             JUnitCore.main(tests.toArray(new String[0]));
         } catch (IOException e) {
@@ -344,10 +346,17 @@ public final class AllTests {
             try {
                 Class<?> c = Class.forName(className, false, contextClassLoader);
 
-                if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) {
+                if (!c.isAnnotation() 
+                        && !c.isEnum() 
+                        && !c.isInterface() 
+                        && !Modifier.isAbstract(c.getModifiers())) 
+                {
                     if (TestCase.class.isAssignableFrom(c)) {
                         isJunitTest =  true;
                     }
+                    else {
+                        isJunitTest = checkForJUnitAnnotations(c);
+                    }
                 }
             } catch (UnsupportedClassVersionError ignored) {
                 log.debug(ignored.getLocalizedMessage());
@@ -360,5 +369,31 @@ public final class AllTests {
             return isJunitTest;
         }
         
+        private boolean checkForJUnitAnnotations(Class<?> clazz)
+        {
+            Class<?> classToCheck = clazz;
+            while(classToCheck != null) {
+                if( checkforTestAnnotationOnMethods(classToCheck)) {
+                    return true;
+                }
+                classToCheck = classToCheck.getSuperclass();
+            }
+            
+            return false;
+        }
+
+        private boolean checkforTestAnnotationOnMethods(Class<?> clazz)
+        {
+            for(Method method : clazz.getDeclaredMethods()) {
+                for(Annotation annotation : method.getAnnotations() ) {
+                    if (org.junit.Test.class.isAssignableFrom(annotation.annotationType())) {
+                        return true;
+                    }
+                }
+            }
+            
+            return false;
+        }
+        
     }
 }