在写作测试中需要帮助

伦敦:

我正在尝试为这个称为Receiver的类编写测试:

public void get(People person) {
            if(null != person) {
               LOG.info("Person with ID " + person.getId() + " received");
               processor.process(person);
             }else{
              LOG.info("Person not received abort!");   
              }
        }

这是测试:

@Test
    public void testReceivePerson(){
        context.checking(new Expectations() {{          
            receiver.get(person);
            atLeast(1).of(person).getId();
            will(returnValue(String.class));        
        }});
    }

注意:receiver是Receiver类的实例(实际不是模拟),processor是Processor类的实例(实际不是模拟),该类处理人员(People类的模拟对象)。GetId是一个不是int的String not int方法,不会出错。

测试失败:person.getId()的意外调用

我正在使用jMock,将不胜感激。据我了解,当我调用此get方法以正确执行方法时,我需要模拟person.getId(),并且我一直在圈子里转了一圈,现在任何帮助都将不胜感激。

Grzenio:

如果我理解正确,那么您必须移动Receiver.get(person);行。在context.checking范围之后-因为这是测试的执行,而不是设置期望。因此,尝试一下:

@Test
public void testReceivePerson(){
    context.checking(new Expectations() {{          
        atLeast(1).of(person).getId();
        will(returnValue(String.class));        
    }});
    receiver.get(person);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章