簡體   English   中英

如何使用@WebMvcTest從上下文中排除包

[英]How to exclude packages from a context using @WebMvcTest

我想測試應用程序片 ,但是我想要排除一個包,因為它根本不與那些測試相關。

我試圖以這種方式排除包:

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

無論如何,此包中的類都包含在上下文中。 怎么解決?

我認為你缺少*在pattern屬性中簽名,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM