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

When using junit5, delay loading testClass and use myown classLoader

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 2.22.1, 3.0.0-M2
    • Fix Version/s: 3.0.0-M4
    • Component/s: JUnit 5.x support
    • Labels:
      None

      Description

      org.junit.platform.engine.discovery.DiscoverySelectors#selectClass(java.lang.String) and org.junit.platform.engine.discovery.DiscoverySelectors#selectClass(java.lang.Class<?>) are different.

      If you use selectClass(java.lang.String) , it will load class by org.junit.platform.engine.discovery.ClassSelector#getJavaClass. The code is as follow:

      {{public Class<?> getJavaClass() { if (this.javaClass == null)

      { this.javaClass = ReflectionUtils.loadClass(this.className).orElseThrow( () -> new PreconditionViolationException("Could not load class with name: " + this.className)); }

      return this.javaClass; } }}

      And the classloader fetched by Thread.currentThread().getContextClassLoader() will load this class. In this way, it will delay  loading class 

      But selectClass(java.lang.Class<?>) will get class directly. 

       

      In my situation, I need load Class by another classLoader so i need to delay loading testClass.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tibordigana Tibor Digana
                Reporter:
                victory Victory Cao
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m