Testing Fragment scenario (ch 9)

You’ve got two issues here:

  • Use launchFragmentInContainer instead of launchFragment when creating your scenario. If you want to test your UI within your Fragment you need to use that API. See: Test your fragments  |  Android Developers
  • Do not use scenario.onFragment {} when doing your check. That function is only needed if you need to call functions or access properties within the Fragment. You do not need it to perform Espresso validations. Pull that onView()... code out of that scenario.onFragment {} lambda expression and just invoke it the same way that you did when you clicked the checkbox.

I hope that helped.