Android: button check enabled

I am having problems testing my application. I created an espresso test that should fail, because whenever I run my application in the emulator, I get the expected behavior. There is my test:

onView(withText("wrong answer")).perform(click()); onView(withId(R.id.nextQuestionButton)).check(matches(isEnabled())); 

When the test starts, nothing is reported, while nextQuestionButton should not turn on when you click on the radioButton, the text of which is the "wrong answer".

+7
java android android-studio android-espresso espresso
source share
1 answer

According to what I understand, you want it to work as follows:

if nextQuestionButton enabled, then do the following:

  • click "wrong answer"
  • check if the nextQuestionButton value specified in NOT has changed.

If so, the code should look like this:

 onView(withId(R.id.nextQuestionButton)).check(matches(isEnabled())); onView(withText("wrong answer")).perform(click()); onView(withId(R.id.nextQuestionButton)).check(matches(not(isEnabled()))); 

Espresso allows you to use Hamcrest tests in tests.

Short description Hamcrest 1.3 .

Also check this out (if you haven't already):

Espresso 2.1. Espresso Cheat Sheet Master

According to this snippet of your message:

When the test starts, nothing is reported, while nextQuestionButton should not be activated when you click radioButton , the text of which is the โ€œwrong answerโ€.

This means that you have not turned off your next question, so Espresso passes this test.

+16
source share

All Articles