@WebAppConfiguration
@WebAppConfiguration是一个注解,可以应用于测试类来声明
该ApplicationContextloaded for an integration test 应为WebApplicationContext.仅仅存在@WebAppConfiguration在 test 类上
确保WebApplicationContext为测试加载,使用默认值"file:src/main/webapp"对于 Web 应用程序根目录的路径(即
resource base path) 的 Sample。资源基路径在后台用于创建MockServletContext,它用作ServletContext对于测试的WebApplicationContext.
以下示例演示如何使用@WebAppConfiguration注解:
-
Java
-
Kotlin
@ContextConfiguration
@WebAppConfiguration (1)
class WebAppTests {
// class body...
}
| 1 | 这@WebAppConfiguration注解。 |
@ContextConfiguration
@WebAppConfiguration (1)
class WebAppTests {
// class body...
}
| 1 | 这@WebAppConfiguration注解。 |
要覆盖默认值,您可以使用
含蓄value属性。双classpath:和file:资源前缀为
支持。如果未提供资源前缀,则假定该路径为文件系统
资源。下面的示例展示了如何指定 Classpath 资源:
-
Java
-
Kotlin
@ContextConfiguration
@WebAppConfiguration("classpath:test-web-resources") (1)
class WebAppTests {
// class body...
}
| 1 | 指定 Classpath 资源。 |
@ContextConfiguration
@WebAppConfiguration("classpath:test-web-resources") (1)
class WebAppTests {
// class body...
}
| 1 | 指定 Classpath 资源。 |
请注意,@WebAppConfiguration必须与@ContextConfiguration,在单个测试类或测试类中
等级制度。请参阅@WebAppConfigurationjavadoc 了解更多详情。