java – 如何使用@WebMvcTest从上下文中排除包
发布时间:2020-12-15 02:17:28  所属栏目:Java  来源:网络整理 
            导读:我想 test application slices,但有一个我想要排除的包,因为它与那些测试根本没有关系. 我试图以这种方式排除包: @RunWith(SpringRunner.class)@WebMvcTest(controllers = MyController.class,excludeFilters = {@ComponentScan.Filter( type = FilterType.
                
                
                
            | 
 我想 
 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 ...
}(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
