天天看點

java中的web怎麼test_java – 如何使用@WebMvcTest從上下文中排除包

我想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 ...

}

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

解決方法:

我認為你缺少*在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 ...

}

标簽:java,spring,testing,spring-boot-2

來源: https://codeday.me/bug/20190711/1429268.html