首页 > 解决方案 > 用于活动的 Android Studio 单元测试

问题描述

我正在关注本教程https://www.youtube.com/watch?v=_TR6QcRozAg ,这是我第一次进行 android studio 活动单元测试,但在代码中出现了一些错误,其中“ActivityTestRule”和“getClass()”显示为红色.无法运行代码

package e.asus.supershop;

import android.view.View;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.*;

public class LoginActivityTest {

    @Rule
    public ActivityTestRule<LoginActivity> mActivityTestRule = new ActivityTestRule<LoginActivity>(LoginActivity.class);

    private LoginActivity mActivity = null;
    @Before
    public void setUp() throws Exception {

        mActivity = mActivityTestRule.getClass();
    }
    @Test
    public void testLaunch()
    {
        View view = mActivity.findViewById(R.id.buttonSignin);
        assertNotNull(view);

    }
    @After
    public void tearDown() throws Exception {
        mActivity = null;
    }
}

标签: androidjunit4

解决方案


推荐阅读