Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot通过了应该失败的测试用例_Java_Spring Boot_Junit - Fatal编程技术网

Java Spring Boot通过了应该失败的测试用例

Java Spring Boot通过了应该失败的测试用例,java,spring-boot,junit,Java,Spring Boot,Junit,我在Spring Boot应用程序中添加了一个测试用例。但是,当我/gradlew build时,所有测试用例都通过了。有什么原因吗 @Test public void testIntentionalError() throws Exception { boolean thrown = true; assertThat(!thrown); } 因为你的测试没有测试任何东西 试试这个: @Test public void testIntentionalError() throws

我在Spring Boot应用程序中添加了一个测试用例。但是,当我
/gradlew build
时,所有测试用例都通过了。有什么原因吗

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertThat(!thrown);
}

因为你的测试没有测试任何东西

试试这个:

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertTrue(!thrown);
}

因为你的测试没有测试任何东西

试试这个:

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertTrue(!thrown);
}

您可以尝试以下操作(如果您想使用assertThat方法):


使用hamcrest matcher(导入static org.hamcrest.core.Is.Is)

您可以尝试以下方法(如果您想使用assertThat方法):


使用hamcrest matcher(import static org.hamcrest.core.Is.Is)

您确定正在运行这个测试用例吗。您可以使用一些配置文件来定义要运行的测试用例子集。我确信它们正在运行,因为在构建之后,reports index.html会以绿色显示所有已通过的测试用例!尝试
assertThat(!抛出).isTrue()为什么需要这样的测试?您是否正在测试
boolean
values赋值在JVM中运行良好?@tmarwen否。我有一个函数,我确信该函数对某个输入返回false。因此,不是false,而是一个函数调用。我只是删除了它以使代码更具可读性。您确定正在运行此测试用例吗。您可以使用一些配置文件来定义要运行的测试用例子集。我确信它们正在运行,因为在构建之后,reports index.html会以绿色显示所有已通过的测试用例!尝试
assertThat(!抛出).isTrue()为什么需要这样的测试?您是否正在测试
boolean
values赋值在JVM中运行良好?@tmarwen否。我有一个函数,我确信该函数对某个输入返回false。因此,不是false,而是一个函数调用。我只是删除了它,让代码更可读。谢谢!我在早上5点编码,所以我绝对没有看到!谢谢我在早上5点编码,所以我绝对没有看到!