Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android studio上导入ID为的浓缩咖啡?_Android_Android Studio_Android Espresso - Fatal编程技术网

如何在android studio上导入ID为的浓缩咖啡?

如何在android studio上导入ID为的浓缩咖啡?,android,android-studio,android-espresso,Android,Android Studio,Android Espresso,我正在尝试为我的应用程序编写一个使用espresso的单元测试,但每当我尝试使用withId时,都找不到它。我该如何解决这个问题 onView工作正常,但当我尝试onView(带ID)时,它不工作 这是我的密码: package com.example.webowner.authenticate; import android.content.Context; import android.content.Intent; import android.support.test.Instrume

我正在尝试为我的应用程序编写一个使用espresso的单元测试,但每当我尝试使用withId时,都找不到它。我该如何解决这个问题

onView工作正常,但当我尝试onView(带ID)时,它不工作

这是我的密码:

package com.example.webowner.authenticate;

import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.;


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

import static org.junit.Assert.*;

public class MainActivityTest {

    @Rule
    public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class);

    @Test
    public void testLoginButton_shouldBeDisplayed()
    {
        //
    }

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }
}
package com.example.webowner.authenticate;
导入android.content.Context;
导入android.content.Intent;
导入android.support.test.InstrumentationRegistry;
导入android.support.test.espresso.espresso;
导入android.support.test.rule.ActivityTestRule;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ProgressBar;
导入静态android.support.test.espresso.espresso.onView;
导入静态android.support.test.espresso.espresso。;
导入org.junit.After;
导入org.junit.Before;
导入org.junit.Rule;
导入org.junit.Test;
导入静态org.junit.Assert.*;
公共类维护活动测试{
@统治
public ActivityTestRule mainActivityActivityTestRule=新的ActivityTestRule(MainActivity.class);
@试验
应显示公共无效测试登录按钮()
{
//
}
@以前
public void setUp()引发异常{
}
@之后
public void tearDown()引发异常{
}
}

您应该导入以下内容:

import static android.support.test.espresso.matcher.ViewMatchers.withId;

希望这能奏效

对于AndroidX,签出包
ViewMatchers

导入androidx.test.espresso.matcher.ViewMatchers.withId


将您的完整代码和所有日志或崩溃(如果存在)放入。