[英]How to exclude packages from a context using @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 : 我认为你缺少*在pattern属性中签名,如下所示:
@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 ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.