Java – how to exclude packages from context using @ webmvctest
•
Java
I want to test application slices, but there is a package I want to exclude because it has nothing to do with those tests
I tried to exclude the package in 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 ... }
In any case, the classes in this package are contained in the context How?
Solution
I think you lack * to sign in the pattern attribute, as shown below:
@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 ... }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码