简体   繁体   中英

Understanding results of Android Espresso instrumentation test

I've created a simple test using Espresso in Android Studio. The test runs to completion and gives a success message.

However, I'm testing to see if two Button views are visible or not. I expect to see that one button is visible and the other is not

The test result does not mention this at all. The goal of this test is to run it via Firebase Test Lab on various virtual and real devices and read the results of the test!

Here is the simple test on Android Studio:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MyGraphingTest {  

@Rule
public ActivityScenarioRule<MainActivity> activityRule
        = new ActivityScenarioRule<>(MainActivity.class); 

@Test
public void MyTestMethod(){

  //some test instructions that will lead me to where the two Button views are...
  //more test instructions that will hide one Button view from screen, while the other Button view remains visible.

    onView(withId(R.id.recenter)).check(matches(isDisplayed()));   
    onView(withId(R.id.buttonGraph2)).check(matches(isDisplayed()));            
}

}

see the attached picture to see the test results!
在此处输入图像描述

All checks "returned" true, so your test is passed. Otherwise, test will fall and you will see the reason of the failure. If you want to see additional information about your checks, you should add some logs mannualy.

However, I'm testing to see if two Button views are visible or not. I expect to see that one button is visible and the other is not

Your test, as you posted it, is looking for both views to be displayed . Keep in mind that visible means View.VISIBILITY == VISIBLE . Displayed means you could actually see it in the current screen. Thus a visible view may not actually be displayed if it's off screen or has a zero width or height.

If you actually want to test visibility , you should use withEffectiveVisibility instead of isDisplayed .

The test result does not mention this at all.

You're testing that both views are displayed and the test passes. What do you expect the test to "mention"? Since your test passed, all the assumptions that are in the test held true and the test result has nothing more to tell you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM