【问题标题】:How to exclude packages from a context using @WebMvcTest如何使用 @WebMvcTest 从上下文中排除包
【发布时间】:2016-11-16 08:48:45
【问题描述】:

我想test application slices,但我想排除一个包,因为它与那些测试完全无关。

我正在尝试以这种方式排除包:

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

这个包中的类无论如何都包含在上下文中。如何解决?

【问题讨论】:

    标签: java spring testing spring-boot


    【解决方案1】:

    我认为您在模式属性中缺少 * 符号,如下所示:

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

    【讨论】:

    • 它不能与 * 一起使用。你试过了吗?我将编辑我的问题
    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 2022-10-19
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    相关资源
    最近更新 更多