Created
April 14, 2016 04:49
-
-
Save suciptoid/56207ae9effc68a49ba85e294e4e07ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pringstudio.cobaandroidtest; | |
import android.test.ActivityInstrumentationTestCase2; | |
import android.test.TouchUtils; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
/** | |
* Created by sucipto on 4/14/16. | |
*/ | |
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity>{ | |
public MainActivityTest(){ | |
super(MainActivity.class); | |
} | |
// Test activity | |
public void testActivityExists(){ | |
MainActivity activity = getActivity(); | |
assertNotNull(activity); | |
} | |
// Test input | |
public void testHello(){ | |
String testString = "Sucipto"; | |
MainActivity activity = getActivity(); | |
// Send Text to edittext | |
final EditText editText = (EditText) activity.findViewById(R.id.editText); | |
getInstrumentation().runOnMainSync(new Runnable() { | |
@Override | |
public void run() { | |
editText.requestFocus(); | |
} | |
}); | |
getInstrumentation().waitForIdleSync(); | |
getInstrumentation().sendStringSync(testString); | |
getInstrumentation().waitForIdleSync(); | |
// Touch The Button | |
Button button = (Button) activity.findViewById(R.id.button); | |
TouchUtils.clickView(this, button); | |
// Verify The Result | |
TextView textView = (TextView) activity.findViewById(R.id.textView); | |
String textResult = textView.getText().toString(); | |
assertEquals("Hello, "+testString+"!",textResult); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment