android - 无法解析符号 assertThat

标签 android android-testing

我的 build.gradle 文件中有以下依赖项

 testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'

我的测试类 EmailValidatorTest 有以下代码

  @Test
public void emailValidator_simpleEmail_returnsTrue(){

   assertThat(EmailValidator.isValidEmail("name@ex.com"),is(true))
}

但我得到的错误是 Cannot resolve symbol assertThat。我只得到 assert 对象。我目前正在处理来自 Android Developers 的示例,即:https://github.com/googlesamples/android-测试/树/master/unit/BasicSample.

最佳答案

确保您导入了 assertThat .

public static <T> void assertThat(T actual,
                                  org.hamcrest.Matcher<T> matcher)

import static org.hamcrest.MatcherAssert.assertThat;

然后清理-重建-运行

关于android - 无法解析符号 assertThat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45586828/

相关文章:

android - 使用矩阵缩放焦点周围 ImageView 的正确方法

Android自签名握手报错

android - Dagger & Android - 测试中的竞争条件?

android - Espresso 如何像在 robotium 中那样不使用 R.id.viewid 访问 View ?

关于获取上下文的 Android ActivityInstrumentationTestCase2 NullPointerException

Android 测试用例顺序

android - 如何使用数据绑定(bind)从 xml 调用 Edittext onEditorAction

android - 调用需要 API 级别 14(当前最小值为 8): android. view.ViewGroup#canScrollHorizo​​ntally

android - Sqlite 数据库在 Samsung Android Oreo 8.0 设备中无法正常运行

android - 如何在开始 Espresso 测试之前准备数据库数据?