-
-
Save jccarbonfive/3127294 to your computer and use it in GitHub Desktop.
This file contains 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
$ cd sample | |
$ ant debug install | |
$ cd ../sampletest | |
$ ant test | |
test: | |
[echo] Running tests ... | |
[exec] | |
[exec] com.sample.GreeterTest: | |
[exec] Failure in testExpectAGreetingAfterSubmittingAName: | |
[exec] junit.framework.AssertionFailedError: Greeting not found | |
... | |
[exec] FAILURES!!! | |
[exec] Tests run: 1, Failures: 1, Errors: 0 |
This file contains 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
$ cd sampletest | |
$ ant debug install | |
$ adb shell am instrument -w -e class com.sample.MainTest com.sample.tests/android.test.InstrumentationTestRunner com.sample.MainTest: | |
Failure in testExpectToIntendToStartANewActivityAfterSubmittingAName: | |
junit.framework.AssertionFailedError: Intent not started | |
... | |
Test results for InstrumentationTestRunner=.F | |
Time: 0.284 | |
FAILURES!!! |
This file contains 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
$ cd sample | |
$ ant debug install | |
$ cd ../sampletest | |
$ adb shell am instrument -w -e class com.sample.MainTest com.sample.tests/android.test.InstrumentationTestRunner ests/android.test.InstrumentationTestRunner | |
com.sample.MainTest:. | |
Test results for InstrumentationTestRunner=. | |
Time: 0.268 | |
OK (1 test) |
This file contains 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
$ ant test | |
test: | |
[echo] Running tests ... | |
[exec] | |
[exec] com.sample.GreeterTest:. | |
[exec] com.sample.MainTest:. | |
[exec] Test results for InstrumentationTestRunner=.. | |
[exec] Time: 4.99 | |
[exec] | |
[exec] OK (2 tests) | |
[exec] | |
[exec] | |
BUILD SUCCESSFUL |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.sample" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> | |
<activity android:name="Main" | |
android:label="@string/app_name"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name="Greeting" /> | |
</application> | |
</manifest> |
This file contains 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.sample; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
public class Greeting extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Intent intent = getIntent(); | |
String name = intent.getStringExtra("name"); | |
String greeting = String.format("Hello %s", name); | |
TextView textView = new TextView(this); | |
textView.setText(greeting); | |
setContentView(textView); | |
} | |
} |
This file contains 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.sample; | |
import android.app.Activity; | |
import android.os.Bundle; | |
public class Main extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
} | |
} |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
> | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
/> | |
<Button | |
android:id="@+id/submit" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="Submit" | |
/> | |
</LinearLayout> |
This file contains 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.sample; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class Main extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Button button = (Button) findViewById(R.id.submit); | |
button.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View view) { | |
EditText editText = (EditText) findViewById(R.id.name); | |
String name = editText.getText().toString(); | |
Intent greeting = new Intent(Main.this, Greeting.class); | |
greeting.putExtra("name", name); | |
startActivity(greeting); | |
} | |
}); | |
} | |
} |
This file contains 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.sample; | |
import android.test.ActivityUnitTestCase; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.widget.EditText; | |
import android.widget.Button; | |
public class MainTest extends ActivityUnitTestCase<Main> { | |
public MainTest() { | |
super(Main.class); | |
} | |
public void testExpectToIntendToStartANewActivityAfterSubmittingAName() { | |
Intent intent = new Intent(getInstrumentation().getTargetContext(), | |
Main.class); | |
startActivity(intent, null, null); | |
Activity activity = getActivity(); | |
String name = "Test User"; | |
EditText editText = (EditText) activity.findViewById(R.id.name); | |
editText.setText(name); | |
Button submit = (Button) activity.findViewById(R.id.submit); | |
submit.performClick(); | |
Intent startedIntent = getStartedActivityIntent(); | |
assertNotNull("Intent not started", startedIntent); | |
assertEquals(name, startedIntent.getStringExtra("name")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment