解决方案是 setActivityIntent。
您可以通过向测试的 Activity 发送意图来设置测试项目,如下所示:
public void setUp() throws Exception {
Intent i = new Intent();
i.putExtra("testLetterz", LETTERS);
setActivityIntent(i);
solo = new Solo(getInstrumentation(), getActivity());
}
然后像这样运行测试:
@Smoke
public void testCheckOneWord() throws Exception {
for(int i = 0; i < 5; i++) {
int r = -1;
Movable m;
do {
r++;
m = (Movable) solo.getView(Movable.class, r);
} while(!(m.getLetter() == LETTERS.charAt(i)));
int x = m.getPosX();
int y = m.getPosY();
solo.drag(x, 10, y, 10+i*Movable.getDropSize(), 1);
}
solo.clickOnButton("Check");
boolean expected = true;
boolean actual = solo.searchText("2/10");
assertEquals("The test is not found", expected, actual);
}
在测试的 Activity 中,您读取了意图并使用了返回带有随机字符的字符串的方法,但如果 testLetterz 不为空,则返回 testLetterz。
在此示例中,我将包含字母的视图拖到放置区,然后检查它们是否在单词列表中。
我用过机器人。