Reputation: 1201
I am attempting to run the test from Robolectric.org's Writing Your First Test page. The test in question looks like this:
@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);
}
I get this compile error: Cannot resolve method 'assertThat(android.content.Intent)
.
The two possibilities I see for importing this method are org.hamcrest.MatcherAssert.assertThat
and org.junit.Assert.assertThat
, neither of which have a single-argument assertThat
method as is being used in this Robolectric test.
My app's build.gradle
has these dependencies:
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'
}
What framework/library is this test using?
Upvotes: 8
Views: 5416
Reputation: 899
follow the following and the issue should go away. Put the first line in you gradle build file
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);
}
}
this link should provide more details also Android Studio and Robolectric
Upvotes: 2
Reputation: 20130
It is neither junit
or hamcrest
assertion API. I think it is Android AssertJ
or just AssertJ
:
testCompile 'org.assertj:assertj-core:1.7.1'
Upvotes: 19