@ComponentScan过滤不需要的测试配置类

时间:2017-10-12 05:58:53

标签: java spring

我有一个测试类:

@ComponentScan(basePackageClasses = {MyAppConfig.class}, excludeFilters = {@ComponentScan.Filter(classes = {OtherTest.ConflictsWithAppTestConfig.class})})
...
public class MyAppTest { ... }

和另外一个不相关的测试类:

public class OtherTest {
    @Configuration
    public static class ConflictsWithAppTestConfig { ... }
}

具有以下目录结构:

src/java/com/example
    \_ MyAppConfig.java
    \_ somesubdirectory
        \_ <more spring components>
        ...

test/java/com/example
    \_ MyAppTest.java
    \_ OtherTest.java // with OtherTest.ConflictsWithAppTestConfig

@ComponentScan.Filter允许我在使用OtherTest.ConflictsWithAppTestConfig时停止导入MyAppTest中的@ComponentScan

然而,当我在同一个基础上添加更多测试用例时,维护此排除类列表将相对于@ComponentScan在同一个包下的其他测试类增长。

如何将@ComponentScan过滤器设置为仅包含src目录配置,以便我手动导入test配置?

即。填空:

@ComponentScan(..., excludeFilters = {@ComponentScan.Filter(type=???, pattern=???)}

0 个答案:

没有答案