问题
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