Ant詳しくない俺がやっているので間違っていたらツッコミください。
この辺とか参考
例によってEclipseから適当にプロジェクトを生成。
その時Testプロジェクトも作成
HelloAnt/
├── AndroidManifest.xml
├── assets
├── bin
├── gen
├── proguard.cfg
├── project.properties
├── res
└── src
└── jp
└── omokageru
└── dnk
└── helloant
└── HelloAntActivity.java
HelloAntTest/
├── AndroidManifest.xml
├── assets
├── bin
├── gen
├── proguard.cfg
├── project.properties
├── res
└── src
└── jp
└── omokageru
└── dnk
└── helloant
├── HelloAntActivityTest.java //これは自分で作る
└── test
//HelloAntActivityTest.java
package jp.omokageru.dnk.helloant;
import android.test.ActivityInstrumentationTestCase2;
public class HelloAntActivityTest extends ActivityInstrumentationTestCase2<HelloAntActivity> {
public HelloAntActivityTest() {
super("jp.omokageru.dnk.helloant", HelloAntActivity.class);
// TODO Auto-generated constructor stub
}
public void testText() throws Exception {
assertEquals("Hello World, HelloAntActivity!",
getActivity().getString(jp.omokageru.dnk.helloant.R.string.hello));
}
}
HelloAntとTestの親ディレクトリへ居るとしてAntプロジェクト用にupdate
2012/01/25 修正
http://developer.android.com/guide/developing/testing/testing_otheride.html#UpdateTestProject にある通り、「android update test-project」を使うべきでした。
update test-projectで引数に指定したとおりant.propertiesが生成されます。
android update project -p HelloAnt/ # android update project -p HelloAntTest/ # test-projectの-mは -pからみた相対パスか絶対パスを指定する android update test-project -m ../HelloAnt/ -p HelloAntTest/
そしてTest側にant.propertiesファイルを作成します。
中身はこんな感じ
# HelloAntとHelloAntTestが並列なのでこんな感じ # tested.project.dir=../HelloAnt/ # test-updateにより自動で生成される
あとはエミュレータか、端末がつながっている状態で下記のように実行するとこんな感じです。
# HelloAntTestディレクトリに居るつもり
ant all clean debug install test
# 出力中略
-test-project-check:
test:
[echo] Running tests ...
[exec]
[exec] jp.omokageru.dnk.helloant.HelloAntActivityTest:
[exec] .
[exec] Test results for InstrumentationTestRunner=.
[exec] Time: 0.315
[exec]
[exec] OK (1 test)
[exec]
[exec]
BUILD SUCCESSFUL
Total time: 13 seconds
まあ all cleanが居るかどうかはびみょーなところでしょうけど無くて困るものでもないし…
試しに ant emma debug install test
とか叩いて見ましたが怒られました。
WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
だそうです…
エミュレータ上でとりあえず試してみたらこんな感じでした。
root端末上でやるならばこの辺参考にすれば出来るんでしょうけど、
誰かやってないのかなぁ…(日本語でのまとめ的な意味で)

















