$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தࠃ

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

  3. ࣗݾ঺հ

  4. ಈ࡞؀ڥ § Android Studio 1.0RC4 § JUnit: 4.11 § Android JUnit4: 0.5 ҎԼͷ಺༰͕Android

    Studio 1.0Ͱ΋ಈ͍ͨΑ͚ͬͯͩ 
  5. Step1: repositoryͷ௥Ճ § Android StudioͷσϑΥϧτ͸jCenter § jCenterʹ͸Android JUnit͕ͳ͍ § ࢖༻͢ΔrepositoryʹMaven CentralΛ௥Ճ § {project_root}/build.gradle ΛҎԼͷΑ͏ʹमਖ਼

    allprojects { repositories { + mavenCentral() jcenter() } }
  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}" }
  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” }
  8. Step4: packagingͷઃఆ § jarϑΝΠϧதͷLICENSE.txt͕ڝ߹͢ΔͨΊআ֎ઃఆ͢Δ § {project_root}/app/build.gradleΛमਖ਼ // android { + packagingOptions {

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

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

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

  12. ͓͠·͍