我想验证特定的演员是否添加到意图,但所有的时间,我在单元测试Android意图为空。我有以下的类需要被测试:单元测试中的意图演示Android Mockito
public class TestClass extends SomeNotifier {
private Intent mIntent = new Intent("testintent");
public TestClassConstructor(Context context) {
super(context);
}
@Override
public void notifyChange() {
mIntent.putExtra("Key one", 22);
mIntent.putExtra("Key two", 23);
mIntent.putExtra("Key three", 24);
getContext().sendBroadcast(mIntent);
}
}
并且测试下(我mockIntent尝试为好,但结果是一样的,再额外为null):
@RunWith(MockitoJUnitRunner.class)
public class TestClassTest {
@Mock
Context mMockContext;
@Test
public void sendBroadcastTest() {
ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class);
TestClass testClassNotifier = new TestClass (mMockContext);
testClassNotifier.notifyChange();
verify(mMockContext).sendBroadcast(argument.capture());
Intent intent = argument.getValue();
//THE INTENT IS NULL
Assert.assertTrue(intent.hasExtra("Key one"));
}
}
你有什么建议我应该如何使这个测试工作? 在此先感谢