Android tests

Android unit testing
see Android Hello World http://osll.spb.ru/projects/geo2tag/wiki/_android_hello_

Android tests example
bac1ca@bac1ca:~/programming/repo/geo2tag/playground/AndroidHelloTests$ ls -1 MyAndroidAppProject MyAndroidAppProjectTest
 * See android tests example in our geo2tag project on Github
 * playground/AndroidHelloTests/

Example classes
public class MyAndroidAppActivity extends Activity{ /** Called when the activity is first created. */   @Override public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState); setContentView(R.layout.main); setTitle(TITLE); }   public static final String TITLE = "Test title..."; }
 * class MyAndroidAppActivity in MyAndroidAppActivity/com/example/myandroid

public class MyAndroidAppActivityTest extends ActivityInstrumentationTestCase {
 * test class MyAndroidAppActivityTest in MyAndroidAppActivityTest/com/example/myandroid/test
 * we test the existence of MyAndroidAppActivity and the title of MyAndroidAppActivity

public MyAndroidAppActivityTest { super("com.example.myandroid", MyAndroidAppActivity.class); }   public void testControlsCreated { Activity activity = getActivity; assertNotNull(activity); }   public void testTitleGood { Activity activity = getActivity; assertEquals(activity.getTitle, MyAndroidAppActivity.TITLE); }

public void testTitleBad { Activity activity = getActivity; assertEquals(activity.getTitle, MyAndroidAppActivity.TITLE + 1); } }

Run test
ant run-tests
 * Go to MyAndroidAppActivityTest project and run ant test target

run-tests: [echo] Running tests ... [exec] Can't dispatch DDM chunk 46454154: no handler defined [exec] Can't dispatch DDM chunk 4d505251: no handler defined [exec] [exec] com.example.myandroid.test.MyAndroidAppActivityTest:. [exec] Failure in testTitleBad: [exec] junit.framework.AssertionFailedError: expected: but was: [exec] 	at com.example.myandroid.test.MyAndroidAppActivityTest.testTitleBad(MyAndroidAppActivityTest.java:26) [exec] 	at java.lang.reflect.Method.invokeNative(Native Method) [exec] 	at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:182) [exec] 	at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:172) [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164) [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151) [exec] 	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:418) [exec] 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1520) [exec] .. [exec] Test results for InstrumentationTestRunner=..F.. [exec] Time: 6.438 [exec] [exec] FAILURES!!! [exec] Tests run: 4, Failures: 1,  Errors: 0 [exec] [exec]
 * result

More about testing

 * http://developer.android.com/guide/developing/testing/testing_otheride.html
 * http://developer.android.com/guide/topics/testing/testing_android.html