junit5 test detection support

#1 Merged at cc842ed
Repository
spags
Branch
junit5
Repository
openclover
Branch
default
Author
  1. James Spagnola
Reviewers
Description

Here’s an initial pass at junit5 test detection. I’m having trouble running the ant build steps to get workable test. However, the changes seek to address the following

  1. Junit5 has changed it’s packaging to org.junit.jupiter.api
  2. Replaced annotation Ignored → Disabled
  3. Junit5 Methods need to non private and non static (i.e. package private is sufficient so we no longer need to enforce public)

Some other things I notice about test detection but out of the scope of JUnit5

  1. Testng doesn’t seem to require any visibility modifier on the method, running in intellij, unless the following
  2. Does TestNG detection handle @Test on the class without @Test on public methods?
  3. Test Detection doesn’t seem to ignore static

Comments (18)

  1. James Spagnola author

    Hi, is there a more formal review process to go through for PR’s? This probably isn’t production ready but I’m eager to get feedback.

  2. Marek Parfianowicz

    Yes I will review it, thank you for your contribution. Please give me some time, I want to release 4.3.1 first. Regards

  3. Dmitry Timofeev

    Thanks for the PR!
    Such method might simplify the code in DefaultTestDetector, avoiding repeated modifiers.containsAnnotation():

    Index: clover-core/src/main/java/com/atlassian/clover/registry/entities/Modifiers.java
    ===================================================================
    --- clover-core/src/main/java/com/atlassian/clover/registry/entities/Modifiers.java (revision 136:d7ff7928299203fad5e5e3f00a7487d267aef5ac)
    +++ clover-core/src/main/java/com/atlassian/clover/registry/entities/Modifiers.java (revision 136+:d7ff79282992+)
    @@ -60,6 +60,18 @@
         @NotNull
         private Map<String, Collection<Annotation>> annotations = newHashMap();
    
    +    /**
    +     * Returns true if the element is annotated with any of the specified annotations.
    +     */
    +    public boolean containsAnyAnnotation(@NotNull String... annotationNames) {
    +        for (String annotationName : annotationNames) {
    +            if (annotations.containsKey(annotationName)) {
    +                return true;
    +            }
    +        }
    +        return false;
    +    }
    +
         public boolean containsAnnotation(@NotNull String name) {
             return annotations.containsKey(name);
         }
    
    1. Marek Parfianowicz

      I like your idea. I would change method signature to

      public boolean containsAnnotation(@NotNull String ... annotationNames)
      

      in order to have it consistent with already existing ones:

      public boolean containsAnnotation(@NotNull Pattern pattern)
      public boolean containsAnnotation(@NotNull String name)
      
  4. Marek Parfianowicz

    We would need an update of the unit test too:

    clover/clover-core/src/test/groovy/com/atlassian/clover/instr/tests/DefaultTestDetectorTest.groovy

    Could you add a testJUnit5 method similar to the testJUnit4 one?

    1. James Spagnola author

      I can. The gotchya I had was that I wasn’t able to build and run the tests for the project. I wasn’t familiar enough ant to figure it out. Are there steps you can provide or link me to get the project running? Thanks.

    2. James Spagnola author

      Hi @marek-parfianowicz .

      Bumping my old message in case you missed it.
      I’d gladly add tests. The gotchya I had was that I wasn’t able to build and run the tests for the project. I wasn’t familiar enough with ant to figure out how to get the build running. Are there steps you can provide or link me to get the project running?

      Thanks.

      1. Marek Parfianowicz

        Hi James. I’m sorry, I missed your previous message somehow.

        You can find instructions how to set up environment here: http://openclover.org/doc/manual/latest/developer-guide--core-ant-eclipse-idea-plugins.html . In the manual it’s written that JDK 1.6 is required, but you can use JDK 1.7-1.9 too.

        After you complete instructions you can run either unit tests from IntellIJ IDEA or from a command line, e.g. “ant clover-core.test clover-ant.test”

  5. James Spagnola author

    Hi @marek-parfianowicz .

    I’ve added a unit test for junit5. It seems like my new test is passing but I have

    BUILD FAILED
    /Users/James.Spagnola/dev/clover/build.xml:50: The following error occurred while executing this line:
    /Users/James.Spagnola/dev/clover/build.xml:32: The following error occurred while executing this line:
    /Users/James.Spagnola/dev/clover/build.xml:18: The following error occurred while executing this line:
    /Users/James.Spagnola/dev/clover/clover-idea/build.xml:188: The following error occurred while executing this line:
    /Users/James.Spagnola/dev/clover/clover-idea/testproject/build.xml:24: Class not found: com.atlassian.clover.ant.taskdefs.CloverCompilerAdapter
    
      1. James Spagnola author

        Thanks.

        Build message returns successful. Should I be concerned about these messages? Otherwise things look good

            [junit] ERROR: Not disposed pointer: jar:///Users/James.Spagnola/.ant/lib/clover.jar!/
        
            1. Marek Parfianowicz

              It's all OK, thank you. I just want test it locally before merge it. Next week probably.