简体   繁体   English

Robolectric的新手,首次测试

[英]New to Robolectric, first test

Hi I'm trying to get into testing using Robolectric. 嗨,我正在尝试使用Robolectric进行测试。 I've set up a button that simply sets another views visibility to visible and I'm trying to test to see if that has occurred. 我已经设置了一个按钮,该按钮仅将另一个视图的可见性设置为“可见”,并且我正在尝试测试是否发生了这种情况。 But my test always fails. 但是我的测试总是失败。 this is what I have so far: 这是我到目前为止所拥有的:

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
public class MyActivityTest {

    private MainAct mActivity;

    @Before
    public void setup() {
        mActivity = Robolectric.buildActivity(MainAct.class).create().get();
    }


    @Test
    public void myActivityAppearsAsExpectedInitially() {
        //mActivity.fab.performClick();

        FloatingActionButton floatingActionButton = (FloatingActionButton) mActivity.findViewById(R.id.fab);
        floatingActionButton.performClick();

        TextView appbar = (TextView) mActivity.findViewById(R.id.searchheader);
        assertThat(appbar).hasText("aidanmack");
    }
}

Unfortunately according to the test, the visibility is still set to "gone". 不幸的是,根据测试,可见性仍然设置为“消失”。

But that isn't the case when I run the app. 但是,当我运行该应用程序时,情况并非如此。

What am I doing wrong? 我究竟做错了什么?

Robolectric allows you to run tests on the JVM. Robolectric允许您在JVM上运行测试。

The instrumentation test you're trying to run must be performed on a device or emulator using connectedAndroidTest - check out the Espresso framework. 您要运行的检测测试必须使用connectedAndroidTest在设备或仿真器上执行-查看Espresso框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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