$30 off During Our Annual Pro Sale. View Details »

AndroidをJUnit4でやる / Using JUnit4 with Android

ryosms
December 06, 2014

AndroidをJUnit4でやる / Using JUnit4 with Android

「AndroidでJUnit4を使う方法 - Qiita」
http://qiita.com/AbeHaruhiko/items/8b3b11421b431d219617

の内容をAndroid Studio 1.0RCでやってみただけ

ryosms

December 06, 2014
Tweet

More Decks by ryosms

Other Decks in Technology

Transcript

  1. AndroidΛJUni4Ͱ΍Δ
    2014/12/06 @GDGதࠃ

    View Slide

  2. ࣗݾ঺հ
    @ryosms
    § ύιίϯަྲྀձʢԬࢁGitϢʔβձʣ
    § ޻ࣄͷ͓͡͞Μ

    View Slide

  3. ࣗݾ঺հ

    View Slide

  4. ಈ࡞؀ڥ
    § Android Studio 1.0RC4
    § JUnit: 4.11
    § Android JUnit4: 0.5
    ҎԼͷ಺༰͕Android Studio 1.0Ͱ΋ಈ͍ͨΑ͚ͬͯͩ

    View Slide

  5. Step1: repositoryͷ௥Ճ
    § Android StudioͷσϑΥϧτ͸jCenter
    § jCenterʹ͸Android JUnit͕ͳ͍
    § ࢖༻͢ΔrepositoryʹMaven CentralΛ௥Ճ
    § {project_root}/build.gradle ΛҎԼͷΑ͏ʹमਖ਼
    allprojects {
    repositories {
    + mavenCentral()
    jcenter()
    }
    }

    View Slide

  6. 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}"
    }

    View Slide

  7. Step3: ςετϥϯφʔͷઃఆ
    § ςετϥϯφʔΛJUnit4༻ͷ΋ͷʹஔ͖׵͑Δ
    § {project_root}/app/build.gradleΛमਖ਼
    // android {
    defaultConfig {
    applicationId ”hoge.fuga.hage"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
    + testInstrumentationRunner ↲
    + "com.uphyca.testing.JUnit4InstrumentationTestRunner”
    }

    View Slide

  8. Step4: packagingͷઃఆ
    § jarϑΝΠϧதͷLICENSE.txt͕ڝ߹͢ΔͨΊআ֎ઃఆ͢Δ
    § {project_root}/app/build.gradleΛमਖ਼
    // android {
    + packagingOptions {
    + exclude 'LICENSE.txt'
    + }

    View Slide

  9. Step5: ࣮ߦߏ੒ͷઃఆ
    § Android Studio͔Βςετ༻ͷ࣮ߦߏ੒Λઃఆ͢Δ
    § [Run] ˠ [Edit Configurations…]

    View Slide

  10. Step6: ςετέʔε࡞੒ˍ࣮ߦ
    § JUnit4ܗࣜͰςετΛॻ͘
    § ςετ࣮ߦ
    § (ƅшƅ)řŵŖ

    View Slide

  11. ࢀߟϦϯΫ
    § AndroidͰJUni4Λ࢖͏ํ๏ – Qiita
    ɹ
    § esmasui/AndroidJUnit4 – GitHub

    View Slide

  12. ͓͠·͍

    View Slide