简体   繁体   English

如何使用@WebMvcTest从上下文中排除包

[英]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.

相关问题 使用Spring Boot @WebMvcTest测试时如何从我的上下文中排除其他@Controller - How to exclude other @Controller from my context when testing using Spring Boot @WebMvcTest 将@WebMvcTest 与spring-boot 一起使用时如何排除@Configuration 类? - How to exclude a @Configuration class when using @WebMvcTest with spring-boot? 从SpringBoot WebMvcTest或其他应用程序上下文中扫描WebMvcTest排除PropertySource - Excluding PropertySource from scanning in SpringBoot WebMvcTest or other application context for WebMvcTest 如何在 Spring Boot WebMvcTest 中设置上下文路径 - How to set the context path in Spring Boot WebMvcTest 从proguard中排除包裹 - exclude packages from proguard 如何添加从外部maven依赖项中排除某些包 - How to add exclude certain packages from an external maven dependency 如何在Eclipse中使用EclEmma插件排除类和包 - How to exclude classes and packages using EclEmma plugin in eclipse 如何从Javadoc中排除某些类/程序包/公共成员 - How to exclude certain class/packages/public members from javadoc 如何从maven build jar中排除一组包? - How to exclude a set of packages from maven build jar? 如何以编程方式从 gradle 中的 src/java 中排除顶级包? - How to programmatically exclude top level packages from src/java in gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM