0

Button click perform and calling a method in junit3 is not working. Implementing in junit3 in android fragment is not working?

NoNaMe
  • 6,020
  • 30
  • 82
  • 110

1 Answers1

-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);
}

Example

Andrei T
  • 2,985
  • 3
  • 21
  • 28