이를 시도해보십시오 텍스트 뷰가 텍스트가 포함 된 경우
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.not;
@RunWith(AndroidJUnit4.class)
public class MainActivityInstrumentedTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule =
new ActivityTestRule<>(MainActivity.class);
@Test
public void checkTextView_isDisplayed_and_notEmpty() throws Exception {
// perform a click on the button
onView(withId(R.id.button)).perform(click());
// passes if the textView does not match the empty string
onView(withId(R.id.textView)).check(matches(not(withText(""))));
}
}
시험 만 통과합니다.
위의 코드는 textView가 비어있는 경우 테스트를 통과합니다. textView가 비어있을 때 테스트가 실패하도록하고 싶습니다. 나는 그것의 비어있을 때 통과하기를 원하지 않는다. –
내 대답이 업데이트되었습니다. 다시 시도하고 작동하는지 알려주세요. – chornge
예. 위의 편집 된 코드가 작동했습니다. –