「AndroidでJUnit4を使う方法 - Qiita」 http://qiita.com/AbeHaruhiko/items/8b3b11421b431d219617
の内容をAndroid Studio 1.0RCでやってみただけ
AndroidΛJUni4ͰΔ2014/12/06 @GDGதࠃ
View Slide
ࣗݾհ@ryosms§ ύιίϯަྲྀձʢԬࢁGitϢʔβձʣ§ ࣄͷ͓͡͞Μ
ࣗݾհ
ಈ࡞ڥ§ Android Studio 1.0RC4§ JUnit: 4.11§ Android JUnit4: 0.5ҎԼͷ༰͕Android Studio 1.0Ͱಈ͍ͨΑ͚ͬͯͩ
Step1: repositoryͷՃ§ Android StudioͷσϑΥϧτjCenter§ jCenterʹAndroid JUnit͕ͳ͍§ ༻͢ΔrepositoryʹMaven CentralΛՃ§ {project_root}/build.gradle ΛҎԼͷΑ͏ʹमਖ਼allprojects {repositories {+ mavenCentral()jcenter()}}
Step2: ґଘؔͷՃ§ ςετ༻ͷґଘؔʹJUnitͱAndroid JUnit4ΛՃ͢Δ§ {project_root}/app/build.gradleΛमਖ਼+ project.ext { // dependenciesʹόʔδϣϯΛهड़ͯ͠ՄʢΈͷʣ+ junitVersion = '4.11'+ androidJunitVersion = '0.5'+ }dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile 'com.android.support:appcompat-v7:21.0.2'+ androidTestCompile "junit:junit:${junitVersion}"+ androidTestCompile "com.uphyca:android-junit4:${androidJunitVersion}"}
Step3: ςετϥϯφʔͷઃఆ§ ςετϥϯφʔΛJUnit4༻ͷͷʹஔ͖͑Δ§ {project_root}/app/build.gradleΛमਖ਼// android {defaultConfig {applicationId ”hoge.fuga.hage"minSdkVersion 8targetSdkVersion 21versionCode 1versionName "1.0"+ testInstrumentationRunner ↲+ "com.uphyca.testing.JUnit4InstrumentationTestRunner”}
Step4: packagingͷઃఆ§ jarϑΝΠϧதͷLICENSE.txt͕ڝ߹͢ΔͨΊআ֎ઃఆ͢Δ§ {project_root}/app/build.gradleΛमਖ਼// android {+ packagingOptions {+ exclude 'LICENSE.txt'+ }
Step5: ࣮ߦߏͷઃఆ§ Android Studio͔Βςετ༻ͷ࣮ߦߏΛઃఆ͢Δ§ [Run] ˠ [Edit Configurations…]
Step6: ςετέʔε࡞ˍ࣮ߦ§ JUnit4ܗࣜͰςετΛॻ͘§ ςετ࣮ߦ§ (ƅшƅ)řŵŖ
ࢀߟϦϯΫ§ AndroidͰJUni4Λ͏ํ๏ – Qiitaɹ§ esmasui/AndroidJUnit4 – GitHub
͓͠·͍