약 3 % 시간 실패한 Android UI 테스트를 디버깅하려고합니다.Robotium이 ImageButton 객체를 찾을 수 없어서 때때로 Android UI 테스트가 실패합니다.
우리의 테스트 클래스는 다음과 같이 밖으로 시작 다음과 같이
@RunWith(AndroidJUnit4.class)
public class ActionWidgetAdapterTest {
private Solo solo;
@Rule
public ActivityTestRule<SampleContainer> mActivityRule = new ActivityTestRule<>(SampleContainer.class);
// SampleContainer is used exclusively for the test case and extends AppCompatActivity
@Before
public void setUp() throws Exception {
solo = new Solo(InstrumentationRegistry.getInstrumentation(), mActivityRule.getActivity());
}
@After
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
// rest of class
// [...]
}
문제가 테스트 케이스는 다음과 같습니다
@Test
@LargeTest
@FlakyTest
public void testAddActions() throws Exception {
final ArrayList<Action> actions = new ArrayList<>();
// Action is our in-house version of the Action class from the Leanback library
final Action a1 = new Action(0, "text1", R.drawable.action_button_focused);
final Action a2 = new Action(1, "text2", R.drawable.action_button_focused);
final Action a3 = new Action(0, "text3", R.drawable.action_button_focused);
final Action a4 = new Action(1, "text4", R.drawable.action_button_focused);
actions.add(a1);
actions.add(a2);
actions.add(a3);
actions.add(a4);
// handler for posting to the main thread
Handler mainHandler = new Handler(mActivityRule.getActivity().getBaseContext()
.getMainLooper());
Runnable myRunnable =() -> {
// add actions to adapter
mActivityRule.getActivity().mActionWidgetAdapter.addActions(actions);
};
mainHandler.post(myRunnable);
solo.sleep(1000); // pause to resolve any timing issues
assertTrue(mActivityRule.getActivity().mActionWidgetAdapter.getItemCount() == 4);
// test edge case - navigate all the way to the left
solo.sendKey(Solo.LEFT);
pressUpDownEnter();
solo.sendKey(Solo.LEFT);
pressUpDownEnter();
solo.sendKey(Solo.LEFT);
pressUpDownEnter();
solo.sendKey(Solo.LEFT);
pressUpDownEnter();
solo.sendKey(Solo.LEFT);
assertTrue(solo.getImageButton(0).isFocused());
assertFalse(solo.getImageButton(2).isFocused());
}
테스트 케이스는 대부분의 시간을 전달합니다. 그러나 assertTrue(solo.getImageButton(0).isFocused());
이 실행될 때 오류가 발생할 가능성은 거의 없습니다. Robotium은 이러한 상황이 발생하면 "3 ImageButtons을 찾을 수 없다"고 불평합니다. 이것에 어떤 패턴도없는 것 같습니다. Robotium 프레임 워크를 최신 버전으로 업그레이드했지만 문제가 해결되지 않습니다.
누구나 우리가 잘못하고있는 것을 알고 있습니까?