【发布时间】:2021-01-19 15:52:31
【问题描述】:
我正在使用 Junit 断言。我在使用 assertThat 时遇到问题。下面的代码显示“assertThat”已被删除。 此外,无论我使用什么匹配器,比如 empty,equalsTo 我都会收到错误消息,因为“JunitAssertions 类型的方法 empty() 是未定义的”。 我项目中使用的Junit版本是4.11。
我的问题是使用 assertThat 断言需要做什么?
从我的项目中复制的代码:
package BasicsOfJava.BasicsOfJava;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
public class JunitAssertions {
@Test
public void assertionsInJava()
{
List<String> emptyList = new ArrayList<>();
**assertThat**(emptyList, empty());
Note : In my editor, assertThat is struck.
}
【问题讨论】:
标签: junit junit4 junit5 hamcrest