Spock test together with junit 5 test does not run

前端 未结 1 1355
一生所求
一生所求 2021-01-21 10:42

My stack:

  • IDEA 2019.1.3
  • Springboot 2.1.6
  • Java 11
  • Maven 3.8.0
  • Groovy 2.5
  • Spock 1.3
  • Junit jupiter 5.5.1
相关标签:
1条回答
  • 2021-01-21 11:21

    This is what I see in IDEA:

    So maybe you want to get more specific and share an MCVE, i.e. a full Maven project with a few dummy classes and tests (both Spock and JUnit), on GitHub for me to inspect.


    Update: After inspecting and fixing your MCVE in my fork I can explain what was wrong:

    1. Your MCVE folder for Spock tests was 'src/test/spock'. I renamed it to 'src/test/groovy' in order to enable GMavenPlus to find it. This fixes Groovy test compilation.

    2. In your POM you manually overrode the dependency versions for three JUnit Jupiter artifacts, but mvn help:effective-pom showed me that some others still were on 5.3.2 while your version was 5.5.1. I am not sure why you think you need to update them other than wishing to be bleeding edge and always use the latest version. Anyway, the effective POM also shows that there are these JUnit-related version properties in your parent POM:

    <junit-jupiter.version>5.3.2</junit-jupiter.version>
    <junit.version>4.12</junit.version>
    

    More exactly, those properties are from your parent POM's own parent POM. The rest was easy: Just override the relevant property in your own POM:

    <properties>
      <junit-jupiter.version>5.5.1</junit-jupiter.version>
    </properties>
    

    Now run mvn clean test and see that both JUnit and Spock tests are being compiled and run. Running the tests from IntelliJ IDEA like in my screenshot above also works now.

    I also sent you a pull request via GitHub.

    0 讨论(0)
提交回复
热议问题