如何使用@WebMvcTest 从上下文中排除包 [英] How to exclude packages from a context using @WebMvcTest
本文介绍了如何使用@WebMvcTest 从上下文中排除包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想测试应用程序切片,但我想排除一个包,因为它与那些测试完全无关.
I want to test application slices, but there is a package I want to exclude, since it is not related to those tests at all.
我试图以这种方式排除包:
I am trying to exclude the package this way:
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = MyController.class,
excludeFilters = {@ComponentScan.Filter(
type = FilterType.REGEX, pattern = "com.foo.bar.*")})
public class MyControllerTest {
// ... list of test methods goes here ...
}
这个包中的类无论如何都包含在上下文中.如何解决?
Classes from this package are included in a context anyway. How to fix it?
推荐答案
我觉得你在模式属性中缺少 * 符号,像这样:
I think you are missing * sign in the pattern attribute, like this :
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = MyController.class,
excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.foo.bar.*")})
public class MyControllerTest {
// ... list of test methods goes here ...
}
这篇关于如何使用@WebMvcTest 从上下文中排除包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文