Button click perform and calling a method in junit3
is not working.
Implementing in junit3
in android fragment is not working?
Asked
Active
Viewed 503 times
0

NoNaMe
- 6,020
- 30
- 82
- 110

user1395988
- 1
- 1
1 Answers
-1
The way we do unit testing at my current workplace is by using Robolectric.
This is more UI testing than unit testing. Also we use expresso. In past I also used Calabash.
//we use Junit4 like in the tutorial.
private static final String DEFAULT_TEXT = "Whatever";
@Before
public void testSetup(){
YourActivity activity = Robolectric.buildActivity(MainActivity.class).get();
}
@After
public void tearDown(){
activity = null;
}
@Test
public void testOnClick() {
TextView textView = (TextView) activity.findViewById(R.id.textView);
Button button = (Button) activity.findViewById(R.id.button);
editText.setText(DEFAULT_TEXT);
button.performClick();
assertThat(textView).containsText(DEFAULT_TEXT);
}

Andrei T
- 2,985
- 3
- 21
- 28
-
The question is asking for fragments, not activities – Akhil Ghatiki Apr 03 '19 at 17:21