Espresso 意图测试中 stubAllExternalIntents() 的用途
Purpose of stubAllExternalIntents() in Espresso intents testing
查看Google sample for intents中的以下方法:
@Before
public void stubAllExternalIntents() {
// By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
// every test run. In this case all external Intents will be blocked.
intending(not(isInternal())).respondWith(new ActivityResult(Activity.RESULT_OK, null));
}
我看到所有外部 intent 都将被阻止,但我想知道此方法的用途是什么?
它不会阻止这些意图,而是将这些意图设置为记录下来,而不是传递给 android 的意图框架。稍后您可以使用 intended() 方法检查所有意图的记录。它也可以用于内部意图。
您想执行密封测试,这意味着您对系统意图不感兴趣,这可能会导致测试不稳定,具体取决于您的断言,这就是为什么您要禁止并非来自您的应用的意图(not(isInternal())
).
查看Google sample for intents中的以下方法:
@Before
public void stubAllExternalIntents() {
// By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
// every test run. In this case all external Intents will be blocked.
intending(not(isInternal())).respondWith(new ActivityResult(Activity.RESULT_OK, null));
}
我看到所有外部 intent 都将被阻止,但我想知道此方法的用途是什么?
它不会阻止这些意图,而是将这些意图设置为记录下来,而不是传递给 android 的意图框架。稍后您可以使用 intended() 方法检查所有意图的记录。它也可以用于内部意图。
您想执行密封测试,这意味着您对系统意图不感兴趣,这可能会导致测试不稳定,具体取决于您的断言,这就是为什么您要禁止并非来自您的应用的意图(not(isInternal())
).