TL;DR
- Maven のプロジェクトに JUnit5 の依存を追加した
- コマンドラインからは通るが、 IntelliJ IDEA からの実行がエラーになる
junit-platform-launcher
を依存に追加したら実行できるようになった
環境
- openjdk 12.0.1
- IntelliJ IDEA 2019.3.2
詳細
公式の 4.2.2. Maven を見て依存を追加。
junit-jupiter-api
と junit-jupiter-engine
を追加。
これでコマンドラインから ./mvnw test
でテストは実行できるようになった。
しかし IDEA から GUI でテスト実行しようとすると下記のようなエラーが出てしまう。
Error:java: エラー: リリース・バージョン5はサポートされていません
junit-platform-launcher
を依存に追加すると解決した。
最終的な pom.xml には下記のような内容が記載してある。
<properties> <maven.compiler.source>12</maven.compiler.source> <maven.compiler.target>12</maven.compiler.target> </properties> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.22.2</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.6.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.6.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-launcher</artifactId> <version>1.6.0</version> <scope>test</scope> </dependency> </dependencies>
4.1.1. IntelliJ IDEA に古いバージョンは junit-platform-launcher
, junit-jupiter-engine
, and junit-vintage-engine
を指定しろと記載しているものの、新しいバージョンではよしなにやってくれそうなことが書いてあるのでよく分からない。