0

我正在开发一个黑莓应用程序,其中我有一个电话监听器,可以检查来电、掉线等内容,并根据此执行一些操作。我想测试一切是否正常工作,所以我正在寻找模拟的方法,例如来电或掉线。有没有办法做到这一点?

4

1 回答 1

1

I would write unit tests with junit and mockito:

public class CallRegistrator implements PhoneListener {
   private final CallLogPersistence persistence;
   public CallRegistrator (CallLogPersistence persistence) {
      this.persistence= persistence;
   }
   ...
}

public class CallRegistratorTest {
   CallLogPersistence  persistence = mock(CallLogPersistence.class);
   CallRegistrator registrator;

   @Before
   public void setUp() {
      registrator = new CallRegistrator(persistence);
   }

   @Test
   public void whenCallFinishedItIsRecoreded() {
      int id = 1;
      registrator.callDisconnected(1);

      verify(persitence).saveFinishedCall(id); 
   }
}

There are also possibility to have automated acceptance test with simulator. It has possibility to simulate incoming call.

于 2012-11-04T11:22:45.040 回答