时更换StricAssertions断言我们有一个进口的问题与Eclipse:Eclipse的组织导入
测试类使用Assertions.assertThat
当按下Ctrl + Shift + O组织进口,Eclipse的替代断言。 assertThat与StrictAssertions.assertThat
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class TheTest {
@Test
public void testName() {
assertThat(2).isEqualTo(2);
}
}
被替换为:
import static org.assertj.core.api.StrictAssertions.assertThat; // change here !
import org.junit.Test;
public class TheTest {
@Test
public void testName() {
assertThat(2).isEqualTo(2);
}
}
而且,当我们有一些仅在断言(用于列表)的特定断言时,Eclipse会将StrictAssertions添加到导入。
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import org.junit.Test;
public class TheTest {
@Test
public void testName() {
assertThat(2).isEqualTo(2);
assertThat(new ArrayList<>()).isEmpty();
}
}
改为:
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.StrictAssertions.assertThat; // this import was added
import java.util.ArrayList;
import org.junit.Test;
public class TheTest {
@Test
public void testName() {
assertThat(2).isEqualTo(2);
assertThat(new ArrayList<>()).isEmpty();
}
}
看来,断言延伸StrictAssertions,所以他们是使用StrictAssertions没有问题的,但为什么就是Eclipse不使用扩展的类?
好吧,看来测试使用 assertThat(文件).hasSameContentAs(refFile); 没有通过任何更多... 但试图检查2个虚拟文件时,它正在工作... – GaspardP
@GaspardP嗯,在我的测试工作。你设置/检查文件编码? – nyname00
那么,我们找到了一个方法: hasSameContent比较V3.2.0中的2个字符串,并与V3.1.0中的二进制文件进行比较。 ,在我们的测试中,我们需要比较二进制文件。 – GaspardP