【发布时间】:2016-10-17 07:55:05
【问题描述】:
JUnit 库有一个类似 Assume.assumeTrue(boolean) 的 Assume.* 指令,它的工作方式类似于断言,但不会导致测试失败而只是被忽略。
我想在测试的arrange 部分中针对我的一个观点执行此类检查,例如假设在开始测试的act 部分之前检查了已建立的复选框。
看看:
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void deselectFilter_AllFiltersSelected_CheckboxAllSelectedUnchecked() {
//arrange
ViewInteraction checkBox = onView(
allOf(withId(R.id.cbCheckAll), isDisplayed()));
//assume that this checkbox is checked
//act
...
//assert
...
}
在arrange 部分,我收到的不是View,而是ViewInteraction。
所以我可以像checkBox.check(matches(isChecked()))那样执行assertion这样的操作
但是如何进行假设呢?
【问题讨论】:
标签: android junit junit4 functional-testing android-espresso