Java – how to exclude packages from context using @ webmvctest

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
分享
二维码
< <上一篇
下一篇>>