首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析symbol assertThat

无法解析symbol assertThat
EN

Stack Overflow用户
提问于 2017-08-09 17:32:40
回答 2查看 11.2K关注 0票数 5

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

代码语言:javascript
复制
 testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'

我的测试类EmailValidatorTest具有以下代码

代码语言:javascript
复制
  @Test
public void emailValidator_simpleEmail_returnsTrue(){

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

但是作为Cannot resolve symbol assertThat,我得到了错误。我只得到了assert对象。我目前正在处理来自Android Developers i的示例,e:https://github.com/googlesamples/android-testing/tree/master/unit/BasicSample

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-09 17:37:47

确保导入了。

代码语言:javascript
复制
public static <T> void assertThat(T actual,
                                  org.hamcrest.Matcher<T> matcher)

导入静态org.hamcrest.MatcherAssert.assertThat;

然后是Clean-Rebuild-Run

票数 9
EN

Stack Overflow用户

发布于 2019-07-15 20:47:47

我也有同样的问题。以下是对我有用的方法:

在app/build.gradle:

代码语言:javascript
复制
testImplementation 'com.google.truth:truth:0.43'

在EmailValidatorTest类中:

代码语言:javascript
复制
import com.google.common.truth.Truth;

在emailValidator_simpleEmail_returnsTrue()方法中:

代码语言:javascript
复制
Truth.assertThat(EmailValidator.isValidEmail("name@ex.com"),is(true))

看,你没有直接导入'assertThat‘,与教程中所说的截然相反。

Here an example.

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45586828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档