-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMyActivityTest.java
37 lines (28 loc) · 1.07 KB
/
MyActivityTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.example.joshskeen.myapplication;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import static org.assertj.android.api.Assertions.assertThat;
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class MyActivityTest {
private MyActivity mActivity;
@Before
public void setup() {
mActivity = Robolectric.buildActivity(MyActivity.class).create().get();
}
@Test
public void myActivityAppearsAsExpectedInitially() {
assertThat(mActivity.mClickMeButton).hasText("Click me!");
assertThat(mActivity.mHelloWorldTextView).hasText("Hello world!");
}
@Test
public void clickingClickMeButtonChangesHelloWorldText() {
assertThat(mActivity.mHelloWorldTextView).hasText("Hello world!");
mActivity.mClickMeButton.performClick();
assertThat(mActivity.mHelloWorldTextView).hasText("HEY WORLD");
}
}