アットウィキロゴ

Android(テスト)

Android(テスト)

テストのやり方


プロジェクトは2つ個別に作る。テスト用は「Androidテスト・プロジェクト」で作成する。
R.idが見つからないのはimportが無いのが原因。以下があるかを確認する。
import jp.main.itinfo.tan.testproject.R;

testInputEditTextでエラーになる場合はAVDがロックされているのが原因。
ロックされていると操作できないため。ロックを解除してテストすると成功する。

antファイルの作り方



C:\android-sdk\sdk\tools>android update test-project -p c:\workspace\TestProject
Test -m c:\workspace\TestProject

Resolved location of main project to: c:\workspace\TestProject
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'TestProjectTest'.
If you wish to change it, edit the first line of build.xml.
Added file c:\workspace\TestProjectTest\build.xml
Updated file c:\workspace\TestProjectTest\proguard-project.txt
Updated ant.properties

これで作成され、ターゲットでtestを選べばテストが出来たけど、エラーが発生する。
test:
    [echo] Running tests ...
    [exec] jp.main.itinfo.tan.testproject.test.TestCase:...
    [exec] Failure in testInputEditText:
    [exec] junit.framework.AssertionFailedError
    [exec] 	at jp.main.itinfo.tan.testproject.test.TestCase.testInputEditText(TestCase.java:77)
    [exec] 	at java.lang.reflect.Method.invokeNative(Native Method)
    [exec] 	at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
    [exec] 	at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
    [exec] 	at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
    [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
    [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
    [exec] 	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)
    [exec] 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
    [exec] Test results for InstrumentationTestRunner=....F
    [exec] Time: 4.355
    [exec] FAILURES!!!
    [exec] Tests run: 4,  Failures: 1,  Errors: 0
BUILD SUCCESSFUL
Total time: 8 seconds

タグ:

+ タグ編集
  • タグ:
最終更新:2013年03月23日 23:29
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。