[英]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.