Skip to content

Instantly share code, notes, and snippets.

@AbeHaruhiko
Created April 10, 2014 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbeHaruhiko/10390864 to your computer and use it in GitHub Desktop.
Save AbeHaruhiko/10390864 to your computer and use it in GitHub Desktop.
AndroidでJUnit4とJUnit3.8やEspressoを併用する方法 ref: http://qiita.com/AbeHaruhiko/items/5416120c8a933f0b8147
<manifest>
<!-- 下記以外は省略しています -->
<instrumentation
android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
android:targetPackage="your.app.package" />
</manifest>
android {
defaultConfig {
// testInstrumentationRunnerの指定を削除する。
// 各flavor内で指定するため。
}
productFlavors {
// JUnit4用のflavor
junit4Test {
// AndroidManifest.xmlで指定する場合は、下記設定は省略可。(junit4Test{} のみ記述)
testInstrumentationRunner "com.uphyca.testing.JUnit4InstrumentationTestRunner"
}
// Espresso用のflavor
espressoTest {
// AndroidManifest.xmlで指定する場合は、下記設定は省略可。(espressoTest{} のみ記述)
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
}
dependencies {
// Espresso関連jar
// 参考: "https://code.google.com/p/android-test-kit/wiki/Espresso#To_use_Espresso_without_dependencies"
// mockitoを使う場合は、hamcrest-core、hamcrest-integrationは入れないらしい。
// 参考: "http://y-anz-m.blogspot.jp/2013/11/android-ui-testing-framework-espresso.html"
// mockitoを使わないなら、standalone版のespresso-1.1-bundled.jarだけ下記libsに入れればOK。
espressoTestCompile fileTree(dir: 'src/espressoTest/libs', include: '*.jar');
espressoTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-library:1.1'
// JUnit4, mockito 関連jar
junit4TestCompile ("org.mockito:mockito-core:1.9.5")
junit4TestCompile ("com.google.dexmaker:dexmaker-mockito:1.+")
junit4TestCompile ("junit:junit:4.+")
junit4TestCompile ("com.uphyca:android-junit4:+")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment