LoginSignup
0
1

More than 3 years have passed since last update.

【SpringBoot】SpringBoot2.0.9 -> 2.1.9でテストを実行できなくなった状況への対処【JUnit5】

Last updated at Posted at 2019-10-13

状況

既存のプロジェクトでSpringBoot2.0.9から2.1.9に上げた所、./mvnw surefire:testを実行するとTestEngine with ID 'junit-jupiter' failed to discover testsするようになってしまいました。

また、ideaからの実行では大半のテストが動くものの、Suppressed: org.junit.platform.commons.util.PreconditionViolationException: Configuration error: You must configure at least one set of arguments for this @ParameterizedTestと出てパラメタライズテストが落ちるようになりました。

その対処としてやったことのまとめです。

試した内容

以下の順で試した所解決しました。

  1. Mavenのアップデート
  2. JUnit5の依存性をjunit-jupiterのみ追加する形へ修正

1. Mavenのアップデート

こちらの記事で「Maven3.6.0未満だとダメ」的な記述が有り、自分の環境のMaven3.5.4だったため、3.6.2へアップデートしました。

これを実行してもその場で症状は変わりませんでしたが、後で何かしら影響が有るかもしれないので、アップデートしておいた方がいいかなと思います。

2. JUnit5の依存性をjunit-jupiterのみ追加する形へ修正

こちらに「junit-jupiter-apijunit-platform-launcherjunit-jupiter-engineの代わりにjunit-jupiterのみをテストの依存関係として使用するとバグが消える」という記述があったため実際にやってみた所、発生していた問題は両方とも解消しました。

pom.xml(修正前の抜粋)
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.5.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.5.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.5.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-params</artifactId>
    <version>5.5.2</version>
    <scope>test</scope>
</dependency>
pom.xml(修正後の抜粋)
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.5.2</version>
    <scope>test</scope>
</dependency>

原因の考察

以下はpom.xml変更後mvn dependency:treeした結果です。

[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.5.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter-api:jar:5.3.2:test
[INFO] |  |  +- org.apiguardian:apiguardian-api:jar:1.0.0:test
[INFO] |  |  +- org.opentest4j:opentest4j:jar:1.1.1:test
[INFO] |  |  \- org.junit.platform:junit-platform-commons:jar:1.3.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter-params:jar:5.3.2:test
[INFO] |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.3.2:test
[INFO] |     \- org.junit.platform:junit-platform-engine:jar:1.3.2:test

これを見ると、junit-jupiter-apijunit-platform-launcherjunit-jupiter-engine5.3.2が入っています。
ここから、原因はライブラリのバージョン間の互換性の問題だと思われます。

参考にさせて頂いた記事

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1