Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Androidのテストよもやま話

 Androidのテストよもやま話

「京都Devかふぇ#5 〜Android Event 2019 リジェクトコン〜」の発表資料です #KyotoDevCafe

https://kyoto-dev-cafe.connpass.com/event/117287/

Sho Ikeda

March 01, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ • εϚʔτϑΥϯΞϓϦ։ൃ • iOS

    / Android / React Native • Swiftίϛολʔ • Kontribute΋ͯ͠Έ͍ͨʂ • https://twitter.com/ikesyo • https://github.com/ikesyo
  2. DroidKaigi 2019 • ΫϩεϓϥοτϑΥʔϜ։ൃ3छͷਆث React Native / TypeScript / GraphQL

    • takuji31͞ΜɺRyo Kitamura͞ΜͱҰॹͷνʔϜͰReact NativeΛॻ͍ͯ ͍·ͨ͠ • ωΠςΟϒͱReact NativeͷϋΠϒϦουΞϓϦ • iOSωΠςΟϒ΋AndroidωΠςΟϒ΋྆ํཧղ͍ͯ͠Δਓ͕͍Δͱྑ ͍ • ಛʹXcode΍GradleͳͲϏϧυγεςϜपΓ
  3. ͱ͍͏༁ʹ͸ߦ͔ͳ͍ͷͰଓ͚·͢ • Local Unit Test (JVM) • JUnit 4, Robolectric

    • src/test • ./gradlew testDevelopDebugUnitTest • Instrumented Test (Emulator/Device) • AndroidJUnitRunner • src/androidTest • ./gradlew connectedDevelopDebugAndroidTest
  4. Robolectric 4.0 and androidx.test • Robolectric 4.0 Released! | Robolectric

    • @RunWith(RobolectricTestRunner::class) -> @RunWith(AndroidJUnit4::class) • 'androidx.test.ext:junit:1.1.0' • Contextͷऔಘํ๏ͷڞ௨ԽͳͲ • Local Unit TestͰ΋Instrumented TestͰ΋ಈ͘ϙʔλϒϧͳ ςετ͕ॻ͚ΔΑ͏ʹ
  5. ͦͯ͠Project Nitrogen΁…… The unification of testing apis between simulators and

    instrumentation opens up a lot of exciting possibilities! Project Nitrogen, which we also announced at Google I/O, will allow you to seamlessly move tests between runtime environments. This means that you will be able to take tests written against the new AndroidX Test APIs and run them on a local JVM, real or virtual device, or even a cloud based testing platform such as Firebase Test Lab. — Write Once, Run Everywhere Tests on Android – Android Developers – Medium
  6. ςετͰͷίʔυڞ༗ def sharedTestSrcDir = "src/sharedTest/java" def sharedTestResDir = "src/sharedTest/resources" sourceSets

    { test { java.srcDirs += sharedTestSrcDir resources.srcDirs += sharedTestResDir } androidTest { java.srcDirs += sharedTestSrcDir resources.srcDirs += sharedTestResDir } }
  7. Spek • Spek Framework • spekframework/spek: A specification framework for

    Kotlin • BDDελΠϧͷςετϑϨʔϜϫʔΫ • JUnit 5ϕʔε • 1.xͱ2.x
  8. Spek object CalculatorSpec: Spek({ describe("A calculator") { val calculator by

    memoized { Calculator() } describe("addition") { it("returns the sum of its arguments") { assertThat(3, calculator.add(1, 2)) } } } })
  9. Spek 2.x • AndroidͰͷ࣮ߦ • Android - Spek Framework •

    android-junit5ͱ͍͏ϓϥάΠϯ͕ඞཁ: https://github.com/ mannodermaus/android-junit5 • READMEʹ͸࣮ݧతͳInstrumentation Test Supportͷهड़͕͋Δ: https://github.com/mannodermaus/android- junit5#instrumentation-test-support • Local Unit Test with RobolectricͰ͸ݫͦ͠͏ʁ
  10. Spek with Robolectric • ৘ใ͓଴͓ͪͯ͠Γ·͢ • ֤ॴͷIssue/PR • Integration with

    spek (kotlin test framework) · Issue #2996 · robolectric/robolectric • Robolectric integration · Issue #65 · spekframework/spek • Robolectric extension to support android unit tests by bangarharshit · Pull Request #324 · spekframework/spek
  11. Spek with Robolectric • Robolectric 4.2 • ϓϥάΠϯγεςϜ΁ͷظ଴ Robolectric 4.2

    introduces a new plugin system, replacing the previous ad-hoc customization mechanisms (subclassing RobolectricTestRunner, providing system properties, etc.). The old mechanisms are deprecated and will eventually be removed; let us know if there are missing extension points you need. See org.robolectric.pluginapi for more details [issue #4362].