【问题标题】:Run as Junit5 is missing in EclipseEclipse 中缺少 Junit5 时运行
【发布时间】:2018-09-07 01:22:21
【问题描述】:

下面是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.myapp</groupId>
<artifactId>backend</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.2.0</version>
    </dependency>
</dependencies>

下面是我的测试用例:

package com.myapp.backend;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class DistanceCalculatorTest {
@Test
public void smokeTest() {
    Location placeABC = new Location(41.3925603, 2.1418532);
    Location placaBCD = new Location(41.3870194,2.1678584);

    // More or less 2km 
    assertEquals(2.0, DistanceCalculator.calculateDistance(placeABC , placaBCD ), 0.5);
  }
}

我没有选择在 Eclipse 中作为 JUnit 5 运行。我正在使用 Eclipse Neon。在运行配置中尝试使用“Junit”时,无法找到测试类。

尝试选择测试类时,出现错误,“在项目构建路径上找不到类'junit.framework.TestCase'”

并且 Maven 依赖项在构建路径中:

这里出了什么问题?

【问题讨论】:

    标签: java eclipse junit


    【解决方案1】:

    JUnit 5 于 2017 年底发布。Neon 的最后一个维护版本是 2017 年初。升级到 Photon。

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 2021-01-11
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多