在Eclipse中缺少作为Junit5运行

时间:2018-09-06 16:37:20

标签: java eclipse junit

下面是我的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”时,无法找到测试类。

enter image description here

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

enter image description here

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

enter image description here

这是怎么回事?

1 个答案:

答案 0 :(得分:1)

JUnit 5于2017年底问世。Neon的最新维护版本是2017年初。升级到Photon。

相关问题