Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-917

[junit] category simple name matching fails throwing ClassNotFoundException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.12.4
    • Fix Version/s: None
    • Component/s: Junit 4.x support
    • Labels:
      None
    • Flags:
      Patch

      Description

      According to a unit test I found JUnit categories/group support should allow matching groups by the category interface simple name along with the fully qualified name.

      Example , given category interfaces:

      category.Fast
      category.Slow
      

      The following commands should be equivalent:

      mvn test -Dgroups="Slow,Fast" 
      mvn test -Dgroups="category.Slow,category.Fast"
      mvn test -Dgroups="category.Slow.class,category.Fast.class"
      

      In my testing, the first command does not work. Instead I get the following exception:

      org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
      java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
      	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
      	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
      Caused by: java.lang.RuntimeException: Unable to load category: Fast
      	at org.apache.maven.surefire.group.match.SingleGroupMatcher.loadGroupClasses(SingleGroupMatcher.java:134)
      	at org.apache.maven.surefire.group.match.JoinGroupMatcher.loadGroupClasses(JoinGroupMatcher.java:44)
      	at org.apache.maven.surefire.common.junit48.FilterFactory.createGroupFilter(FilterFactory.java:92)
      	at org.apache.maven.surefire.junitcore.JUnitCoreProvider.createJUnit48Filter(JUnitCoreProvider.java:183)
      	at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:115)
      	... 9 more
      Caused by: java.lang.ClassNotFoundException: Fast
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      	at org.apache.maven.surefire.group.match.SingleGroupMatcher.loadGroupClasses(SingleGroupMatcher.java:130)
      	... 13 more
      
      

      It seems like if a category name cannot be loaded, it should just be ignored.

      I added an integration test that proves the failure and supplied a patch which avoids the problem to allow specifying the simple class name for matching.

      It would be great to have this working to allow a developer to easily run specific groups of tests in a concise manner.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              plynch Peter Lynch
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: