【问题标题】:How to run JUnit 5 tests in Eclipse如何在 Eclipse 中运行 JUnit 5 测试
【发布时间】:2019-01-30 18:31:38
【问题描述】:

我想在 Eclipse 中运行 JUnit 测试。我试过这个:

我添加了 POM 依赖:

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

JUnit 测试

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
public class DatabaseFeaturesTest {

    @Test
    public void writeData() {
        System.out.println("Converting Map using bitmasking");
    }

    @AfterAll
    public void databaseInsert() {

    }
}

但是当我运行测试时,我得到:

Aug 24, 2018 12:29:23 PM org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder buildRunner
WARNING: Ignoring test class using JUnitPlatform runner: org.rest.api.DatabaseFeaturesTest
Aug 24, 2018 12:29:23 PM org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder buildRunner
WARNING: Ignoring test class using JUnitPlatform runner: org.rest.api.DatabaseFeaturesTest

你能给出一些我错的地方以及如何解决问题的建议吗?

【问题讨论】:

  • 您运行的是什么版本的 Eclipse?根据the docs Eclipse Oxygen.1a (4.7.1a) 中添加了 JUnit5 支持。
  • 我使用版本:Photon Release (4.8.0)
  • @johanneslink 的回答是正确的:您不需要@RunWith(JUnitPlatform.class) 在 Eclipse 4.7.1a 或更高版本中运行基于 JUnit 5 的测试。所以,我建议你接受他的回答。 ;-)

标签: java eclipse junit junit5


【解决方案1】:

摆脱@RunWith(JUnitPlatform.class),这是 JUnit 4 运行 Jupiter 测试的方式。有了 Eclipse 中的 JUnit 5 平台支持,您就不再需要它了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 2021-09-10
    • 2018-09-22
    • 2021-07-03
    • 2012-06-02
    • 1970-01-01
    • 2011-12-15
    相关资源
    最近更新 更多