How to exclude packages from a context using @WebMvcTest

巧了我就是萌 提交于 2019-12-23 12:41:14

问题


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?


回答1:


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 ...
}


来源:https://stackoverflow.com/questions/40627573/how-to-exclude-packages-from-a-context-using-webmvctest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!