How to exclude packages from context using @WebMvcTest

I want to test application slices , but there is a package that I want to exclude, since it is not associated with these tests at all.

I am trying to exclude a package as follows:

@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 the context anyway. How to fix it?

+3
source share
1 answer

I think you are missing the * character in the pattern attribute, for example:

 @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 ... } 
0
source

Source: https://habr.com/ru/post/1262440/


All Articles