Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 为Junit测试注入不同的枚举值_Spring_Junit - Fatal编程技术网

Spring 为Junit测试注入不同的枚举值

Spring 为Junit测试注入不同的枚举值,spring,junit,Spring,Junit,我在要测试的类中定义了一个自动连接bean: @Autowired ContextEnum myContext; 这将在以后使用: if(ContextEnum.A.equals(myContext)) { // do something } else if(ContextEnum.B.equals(myContext)) { // do something } 在我的junits配置中,我将其设置为返回ContextEnum的特定值,如下所示: @Configuration @Lazy p

我在要测试的类中定义了一个自动连接bean:

@Autowired
ContextEnum myContext;
这将在以后使用:

if(ContextEnum.A.equals(myContext)) {
// do something
} else if(ContextEnum.B.equals(myContext)) {
// do something
}
在我的junits配置中,我将其设置为返回ContextEnum的特定值,如下所示:

@Configuration
@Lazy
public class myJunitConfig {
    @Bean
    public ContextEnum getContextEnum() {
       return ContextEnum.A;
    }
}
我的少年:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {
    myJunitConfig.class
})
public class ContextTest {

  @Test
  public void testContextB() {
      Input input = createMock(Input.class);
      expect(input.getId()).return(1L).anyTimes();
      client.getHandle().call();
  }
}
但是,这不允许我测试枚举的不同值。除了在junit上使用setter/constructor注入之外,还有什么方法可以注入不同的枚举值?提前谢谢

与弹簧配合使用