Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.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 测试文件夹在SpringBoot项目中做什么?_Java_Spring_Unit Testing_Spring Boot_Annotations - Fatal编程技术网

Java 测试文件夹在SpringBoot项目中做什么?

Java 测试文件夹在SpringBoot项目中做什么?,java,spring,unit-testing,spring-boot,annotations,Java,Spring,Unit Testing,Spring Boot,Annotations,我刚刚创建了springboot项目,src中有一个名为test的文件夹。它有什么作用 import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class

我刚刚创建了springboot项目,src中有一个名为test的文件夹。它有什么作用

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class GprocApplicationTests {

@Test
public void contextLoads() {
}

}

创建spring启动项目时,该项目的src文件夹中存在test文件夹。在test文件夹中,有一个用@RunWith(SpringRunner.class)@SpringBootTest注释的类。它做什么?

这是项目生成器添加的基本测试

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class GprocApplicationTests {

@Test
public void contextLoads() {
}

}
它的主要目的是为您设置测试基础设施(需要的目录、库等)

此特定测试确保应用程序启动时不会出错(因为您的应用程序还没有执行任何其他操作)。目的是让您在主文件夹中添加功能时,利用此设置添加自己的测试。

Spring Boot遵循这种方法,因此它使用通用的Java项目结构,这在构建系统中很常见


因此,test文件夹包含
src/test/java
下的测试源文件和
src/test/resources
下的测试资源。此外,作为一种良好实践,Spring Boot还包括一个测试类,用于验证应用程序上下文是否正确启动。

它加载Spring上下文,并检查所有依赖项和配置是否以正确的方式完成。如果没有,测试失败。你可以读更多