5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MavenでJUnit5が実行してできなかったのを解決したメモ。

Posted at

環境とバージョン

Java - Java9
Eclipse - Oxygen.1a Release (4.7.1a)
JUnit - JUnit5

MavenプロジェクトでJUnit5を使用するため以下をpom.xmlに記述たあと色々設定した後、JUnitでビルドするとエラーが出たのでその内容と解決方法です。

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.0.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

エラー内容

スクリーンショット 2017-12-12 20.20.17.png
Could not run test

No tests found with test runner 'JUnit5'

Eclipseのコンソール

ava.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:31)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at java.base/java.lang.Class.newInstance(Class.java:558)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:368)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:363)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:307)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:222)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.core.LauncherFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	... 11 more

解決方法

pom.xmlに以下を追加する。

    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.1</version>
        <scope>test</scope>
    </dependency>

JUnit5では3つのサブプロジェクトに別れたため、JUnit5のJUnit Jupiterだけを依存性の定義に追加でしただけでは足りなかったようです。

解決に導いてくれた記事

JUnit5
JUnit 4で消耗しているあなたに贈るJUnit 5入門

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?