Junit 5找不到测试(Spring Boot)

问题描述 投票:1回答:1

我已经通过Spring Initilizr创建了一个Spring Boot 2.2.6应用程序,其中包括JUnit 5.6。我将生成的pom.xml以及一些其他依赖项和Intellij IDEA 2020.1用作我的IDE。

我创建了一个非常简单的测试,只是为了查看测试是否有效:

package com.hua.geoutils;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class GeoUtilsTest
{

    @Test
    public void testSplitBoundingBox()
    {
      Assert.assertEquals(1,1);
    }
}

我执行mvn test spring-boot:run,并在测试生命周期中得到此:

[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ atlantis-rest ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

似乎maven甚至没有检测到测试存在,我不明白为什么。对这里出什么问题有任何想法吗?

java spring-boot maven junit5
1个回答
0
投票

您同时使用JUnit4(Assert)和JUnit 5(@Test)。最初,Maven将尝试确定运行测试所需的提供程序,并以某种方式选择了JUnit4。

编辑测试以使用JUnit5(也称为Juipiter)断言API。将org.junit.Assert.assertEquals(...)更改为org.junit.jupiter.api.Assertions.assertEquals(....)

并且不要忘记在所有测试文件中将org.junit.Assert.*出现次数更改为org.junit.jupiter.api.Assertions.*

© www.soinside.com 2019 - 2024. All rights reserved.