Spring 为Junit测试注入不同的枚举值
我在要测试的类中定义了一个自动连接bean: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
@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注入之外,还有什么方法可以注入不同的枚举值?提前谢谢 与弹簧配合使用