@RunWith(SpringRunner.class)
@SpringBootTest(classes=AsposeWordToHtml.class)
@TestPropertySource("classpath:application.properties") //配置文件注入 @ContextConfiguration(classes=AsposeWordToHtml.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration({"classpath:applicationContext.xml"})
@RunWith(SpringRunner.class)
public class MyControllerTest {
private MockMvc mockMvc;
// 测试方法
}
创建一个Spring上下文,它只包含与web层(控制器、过滤器、转换器等)相关的bean子集:@WebMvcTest
如果您想自动创建一个不是由上面的注释创建的Spring上下文一部分的bean,您可以使用一个@TestConfiguration
来手动将您喜欢的bean添加到测试上下文中
@ActiveProfiles("dev")
@RunWith(MockitoJUnitRunner.class)
@ActiveProfiles("test") @ExtendWith(SpringExtension.class) @Sql(scripts = {"classpath:db/hsqldb/schema.sql", "classpath:db/hsqldb/data.sql"})
@SpringBootTest(properties = "spring.cloud.config.enabled:false", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(MockitoJUnitRunner.class)
@TestPropertySource(locations = "/foo.properties")
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
<dependency\>
<groupId\>org.springframework.boot</groupId\>
<artifactId\>spring-boot-starter-test</artifactId\>
<scope\>test</scope\>
</dependency\>
<dependency\>
<groupId\>com.h2database</groupId\> <!-- 单元测试,我们采用 H2 作为数据库 -->
<artifactId\>h2</artifactId\>
<scope\>test</scope\>
</dependency\>
https://www.cnblogs.com/dyh004/p/11584129.html