Is it possible to assert isDisplayed on multiple views with Espresso?












0














I am wondering if it is possible to create a custom matcher which can take all of the views specified and make an assertion on that array or collection.



As a potential example it would look like:



onView(
(withAllIds(R.id.text_view1,R.id.text_view2, R.id.text_view3))).check(matches(isDisplayed())



For clariy, the above would assert that textview 1, 2, and 3 are all displayed.



Whether or not this is a code smell or not, I am curious to hear thoughts and opinions. I would be using this to make a simple assertion that the expected views are shown at the UI level and perhaps pair it with isCompletelyDisplayed() to ensure nothing is clipped. Writing the tests/assertions separately would allow easier debugging if something fails, but would take longer time in the suite to have every test run separately on the CI.



Optionally, is there a better way to test these simple view assertions? Is it worth it?



I am usually a fan of testing an interaction with the app e.g. if the app actually does something, the UI handles it correctly, or if the API returns a response, then the UI handles it correctly.



But I am curious if using something like the everyItem Hamcrest example is possible for multiple views with Espresso.



Referencing:



http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/core/Every.html



everyItem example from Hamcrest










share|improve this question



























    0














    I am wondering if it is possible to create a custom matcher which can take all of the views specified and make an assertion on that array or collection.



    As a potential example it would look like:



    onView(
    (withAllIds(R.id.text_view1,R.id.text_view2, R.id.text_view3))).check(matches(isDisplayed())



    For clariy, the above would assert that textview 1, 2, and 3 are all displayed.



    Whether or not this is a code smell or not, I am curious to hear thoughts and opinions. I would be using this to make a simple assertion that the expected views are shown at the UI level and perhaps pair it with isCompletelyDisplayed() to ensure nothing is clipped. Writing the tests/assertions separately would allow easier debugging if something fails, but would take longer time in the suite to have every test run separately on the CI.



    Optionally, is there a better way to test these simple view assertions? Is it worth it?



    I am usually a fan of testing an interaction with the app e.g. if the app actually does something, the UI handles it correctly, or if the API returns a response, then the UI handles it correctly.



    But I am curious if using something like the everyItem Hamcrest example is possible for multiple views with Espresso.



    Referencing:



    http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/core/Every.html



    everyItem example from Hamcrest










    share|improve this question

























      0












      0








      0







      I am wondering if it is possible to create a custom matcher which can take all of the views specified and make an assertion on that array or collection.



      As a potential example it would look like:



      onView(
      (withAllIds(R.id.text_view1,R.id.text_view2, R.id.text_view3))).check(matches(isDisplayed())



      For clariy, the above would assert that textview 1, 2, and 3 are all displayed.



      Whether or not this is a code smell or not, I am curious to hear thoughts and opinions. I would be using this to make a simple assertion that the expected views are shown at the UI level and perhaps pair it with isCompletelyDisplayed() to ensure nothing is clipped. Writing the tests/assertions separately would allow easier debugging if something fails, but would take longer time in the suite to have every test run separately on the CI.



      Optionally, is there a better way to test these simple view assertions? Is it worth it?



      I am usually a fan of testing an interaction with the app e.g. if the app actually does something, the UI handles it correctly, or if the API returns a response, then the UI handles it correctly.



      But I am curious if using something like the everyItem Hamcrest example is possible for multiple views with Espresso.



      Referencing:



      http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/core/Every.html



      everyItem example from Hamcrest










      share|improve this question













      I am wondering if it is possible to create a custom matcher which can take all of the views specified and make an assertion on that array or collection.



      As a potential example it would look like:



      onView(
      (withAllIds(R.id.text_view1,R.id.text_view2, R.id.text_view3))).check(matches(isDisplayed())



      For clariy, the above would assert that textview 1, 2, and 3 are all displayed.



      Whether or not this is a code smell or not, I am curious to hear thoughts and opinions. I would be using this to make a simple assertion that the expected views are shown at the UI level and perhaps pair it with isCompletelyDisplayed() to ensure nothing is clipped. Writing the tests/assertions separately would allow easier debugging if something fails, but would take longer time in the suite to have every test run separately on the CI.



      Optionally, is there a better way to test these simple view assertions? Is it worth it?



      I am usually a fan of testing an interaction with the app e.g. if the app actually does something, the UI handles it correctly, or if the API returns a response, then the UI handles it correctly.



      But I am curious if using something like the everyItem Hamcrest example is possible for multiple views with Espresso.



      Referencing:



      http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/core/Every.html



      everyItem example from Hamcrest







      android-espresso






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 19:15









      Mark HanMark Han

      1529




      1529
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268663%2fis-it-possible-to-assert-isdisplayed-on-multiple-views-with-espresso%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268663%2fis-it-possible-to-assert-isdisplayed-on-multiple-views-with-espresso%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma