首页 > 解决方案 > 带有一个参数库的 AssertThat

问题描述

我试图从http://mapstruct.org/#get-started执行测试

他们在那里使用代码

assertThat( carDto ).isNotNull();

由于在许多教程中他们没有为可读性添加 import 子句,而且我不是测试工具的大师,我添加了最新的 junit mvn 依赖项。

    <junit.version>4.12</junit.version>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
    </dependency>

在 Java 中,我添加了导入:

import static org.junit.Assert.assertThat;

Eclipse 抱怨 assertThat 只有一种选择,即

类型 Assert 中的 assertThat(T, Matcher) 不适用于参数 (CarDto)

难道我做错了什么?这是来自我不知道的不同库的方法吗?我在互联网上搜索并找到了一些东西,但我不确定它是否被广泛采用,我想记住这一点,因为我们将在实际项目中使用它。

PS:也试过org.hamcrest.MatcherAssert.assertThat;但它会产生相同的错误,它们的库的签名是相同的。

标签: mavenunit-testingjunit

解决方案


assertThat( carDto ).isNotNull();看起来像 AssertJ,它没有随 JUnit 一起分发。看看这个快速入门


推荐阅读