【问题标题】:JUnit 5 test case result not reflecting even changed the logicJUnit 5 测试用例结果没有反映甚至改变了逻辑
【发布时间】:2020-11-02 18:28:13
【问题描述】:

我正在尝试在 intelliJ IDE 的 spring-boot 应用程序中使用 junit5。当我单独运行它时,我遇到了不反映 junit 测试结果的问题。当我使用 mvn clean install 命令运行时,我的测试用例被执行并且工作正常,但是当我运行它单独的测试用例时,结果保持不变。它总是显示我从 cmd mvn clean install 获得的最后一个结果..即使我已经更改了代码。它没有反映。以下正在使用:

        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>

以下是依赖项:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>

我的测试用例:

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class TestingApplicationTests {
    @Test
    public void contextLoads() {
        assertEquals("abc", "abc");
    }
}

如果我把它改成

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class TestingApplicationTests {
    @Test
    public void contextLoads() {
        assertEquals("abc", "123");
    }
}

如果通过了 mvn install 的最后一个结果,则通过右键单击“运行”再次运行此单个测试。 我的问题是为什么它不反映我的结果?在第二种情况下它应该会失败。

【问题讨论】:

  • 你确定你的IDE已经编译了吗?因为当您运行时,您正在使用 IDE,正如您所说的单击运行,请检查来自 IDE 的警告
  • 是的@vmrvictor 我能够编译它并且没有警告。 :(
  • 你可以试试 mvn clean install
  • 是的,我曾尝试使用 mvn clean install 但没有任何变化。 @techiesantosh
  • 请展示完整的可运行示例。有很多事情会出错,例如过滤掉的类名、错误的导入等。

标签: java spring-boot intellij-idea junit junit5


【解决方案1】:

请务必检查 maven 项目的主模块和子模块中的 Junit 版本。 可能有机会,因此它的行为是这样的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多