[英]importing correct AssertThat method for Robolectric Test
我正在尝试从Robolectric.org的“ 编写您的第一个测试”页面运行测试 。 有问题的测试如下所示:
@Test
public void clickingLogin_shouldStartLoginActivity() {
WelcomeActivity activity = Robolectric.setupActivity(WelcomeActivity.class);
activity.findViewById(R.id.login).performClick();
Intent expectedIntent = new Intent(activity, WelcomeActivity.class);
assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent);
}
我收到此编译错误: Cannot resolve method 'assertThat(android.content.Intent)
。
我看到的用于导入此方法的两种可能性是org.hamcrest.MatcherAssert.assertThat
和org.junit.Assert.assertThat
,这两种方法都没有一个单参数assertThat
方法,该方法已在该Robolectric测试中使用。
我的应用程序的build.gradle
具有以下依赖关系:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
testCompile "org.robolectric:robolectric:3.0"
testCompile 'junit:junit:4.12'
}
该测试使用什么框架/库?
它既不是junit
也不是hamcrest
断言API。 我认为它是Android AssertJ
或只是AssertJ
:
testCompile 'org.assertj:assertj-core:1.7.1'
请执行以下操作,该问题将消失。 将第一行放在您的gradle构建文件中
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'junit:junit:4.12'
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class SomethingTest {
@Test
public void testSomething() {
assertThat(true, 1>1);
}
}
该链接还应提供更多详细信息,以及Android Studio和Robolectric
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.