简体   繁体   English

在Eclipse中缺少作为Junit5运行

[英]Run as Junit5 is missing in Eclipse

Below is my pom.xml: 以下是我的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>

Below is my test case: 下面是我的测试用例:

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);
  }
}

I am not getting the option to run as JUnit 5 in Eclipse. 我没有选择在Eclipse中作为JUnit 5运行的选项。 I am using Eclipse Neon. 我正在使用Eclipse Neon。 When trying to use "Junit" from Run configuration, it is not able to find the test class. 尝试从“运行”配置中使用“ Junit”时,无法找到测试类。

在此处输入图片说明

When trying to select the test class, getting error, " Cannot find class 'junit.framework.TestCase' on project build path" 尝试选择测试类时,出现错误“在项目构建路径上找不到类'junit.framework.TestCase'”

在此处输入图片说明

And the Maven dependencies are in build path: Maven依赖项位于构建路径中:

在此处输入图片说明

What is going wrong here? 这是怎么了?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM