-
-
Save jccarbonfive/3127274 to your computer and use it in GitHub Desktop.
exploring test-driven development in Android
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
| $ export | |
| PATH=$PATH:~/Downloads/android-sdk-macosx/tools:~/Downloads/android-sdk-macosx/platform-tools |
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
| $ android list targets | |
| Available Android targets: | |
| ---------- | |
| id: 1 or "android-16" | |
| Name: Android 4.1 | |
| Type: Platform | |
| API level: 16 | |
| Revision: 1 | |
| Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), | |
| WVGA854, WXGA720, WXGA800, WXGA800-7in | |
| ABIs : armeabi-v7a |
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
| $ android create avd --name sample.android-16 --target android-16 | |
| Auto-selecting single ABI armeabi-v7a | |
| Android 4.1 is a basic Android platform. | |
| Do you wish to create a custom hardware profile [no] | |
| Created AVD 'sample.android-16' based on Android 4.1, ARM (armeabi-v7a) | |
| processor, | |
| with the following hardware config: | |
| hw.lcd.density=240 | |
| vm.heapSize=48 | |
| hw.ramSize=512 |
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
| $ android create project --target android-16 --path sample --package com.sample --activity Main | |
| Created project directory: sample | |
| Created directory /Users/jared/Projects/sample/src/com/sample | |
| Added file sample/src/com/sample/Main.java | |
| Created directory /Users/jared/Projects/sample/res | |
| Created directory /Users/jared/Projects/sample/bin | |
| Created directory /Users/jared/Projects/sample/libs | |
| Created directory /Users/jared/Projects/sample/res/values | |
| Added file sample/res/values/strings.xml | |
| Created directory /Users/jared/Projects/sample/res/layout | |
| Added file sample/res/layout/main.xml | |
| Created directory /Users/jared/Projects/sample/res/drawable-xhdpi | |
| Created directory /Users/jared/Projects/sample/res/drawable-hdpi | |
| Created directory /Users/jared/Projects/sample/res/drawable-mdpi | |
| Created directory /Users/jared/Projects/sample/res/drawable-ldpi | |
| Added file sample/AndroidManifest.xml | |
| Added file sample/build.xml | |
| Added file sample/proguard-project.txt | |
| $ android create test-project --path sampletest --main ../sample | |
| Found main project package: com.sample | |
| Found main project activity: Main | |
| Found main project target: Android 4.1 | |
| Created project directory: sampletest | |
| Created directory /Users/jared/Projects/sampletest/src/com/sample | |
| Added file sampletest/src/com/sample/MainTest.java | |
| Created directory /Users/jared/Projects/sampletest/res | |
| Created directory /Users/jared/Projects/sampletest/bin | |
| Created directory /Users/jared/Projects/sampletest/libs | |
| Added file sampletest/AndroidManifest.xml | |
| Added file sampletest/build.xml | |
| Added file sampletest/proguard-project.txt | |
| $ ls | |
| sample sampletest |
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
| $ cd sampletest | |
| $ wget -P libs http://robotium.googlecode.com/files/robotium-solo-3.3.jar |
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
| <supports-screens android:anyDensity="true"/> |
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.sample; | |
| import android.test.ActivityInstrumentationTestCase2; | |
| import com.jayway.android.robotium.solo.Solo; | |
| public class GreeterTest extends ActivityInstrumentationTestCase2<Main> { | |
| public GreeterTest() { | |
| super("com.sample", Main.class); | |
| } | |
| public void testExpectAGreetingAfterSubmittingAName() { | |
| Solo solo = new Solo(getInstrumentation(), getActivity()); | |
| int editTextIndex = 0; | |
| String name = "Android"; | |
| solo.enterText(editTextIndex, name); | |
| solo.clickOnButton("Submit"); | |
| String greeting = String.format("Hello %s", name); | |
| assertTrue("Greeting not found", solo.searchText(greeting)); | |
| } | |
| } |
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
| $ emulator -avd sample.android-16 |
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
| $ cd sampletest | |
| $ ant debug install |
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
| $ ant test | |
| test: | |
| [echo] Running tests ... | |
| [exec] | |
| [exec] com.sample.GreeterTest: | |
| [exec] Failure in testExpectAGreetingAfterSubmittingAName: | |
| [exec] junit.framework.AssertionFailedError: EditText with index 0 is not available! | |
| ... | |
| [exec] Time: 11.829 | |
| [exec] | |
| [exec] FAILURES!!! | |
| [exec] Tests run: 1, Failures: 1, Errors: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment