Slide 1

Slide 1 text

Androidͷ ςετΑ΋΍·࿩ @ikesyo ژ౎Dev͔;͐#5 ʙAndroid Event 2019 ϦδΣΫτίϯʙ 2019-03-01 Fri #KyotoDevCafe

Slide 2

Slide 2 text

@ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ • εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • Kontribute΋ͯ͠Έ͍ͨʂ • https://twitter.com/ikesyo • https://github.com/ikesyo

Slide 3

Slide 3 text

DroidKaigi 2019 • ΫϩεϓϥοτϑΥʔϜ։ൃ3छͷਆث React Native / TypeScript / GraphQL • takuji31͞ΜɺRyo Kitamura͞ΜͱҰॹͷνʔϜͰReact NativeΛॻ͍ͯ ͍·ͨ͠ • ωΠςΟϒͱReact NativeͷϋΠϒϦουΞϓϦ • iOSωΠςΟϒ΋AndroidωΠςΟϒ΋྆ํཧղ͍ͯ͠Δਓ͕͍Δͱྑ ͍ • ಛʹXcode΍GradleͳͲϏϧυγεςϜपΓ

Slide 4

Slide 4 text

Androidͷςετͷ࿩

Slide 5

Slide 5 text

PEAKSʢϐʔΫεʣʛ Androidςετશॻ

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

2018೥·ͰͷAndroid ςετ૯·ͱΊ - ࠓ೥ͷ มߋͱདྷ೥ͷରࡦ - Qiita

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Fin.

Slide 10

Slide 10 text

ͱ͍͏༁ʹ͸ߦ͔ͳ͍ͷͰଓ͚·͢ • Local Unit Test (JVM) • JUnit 4, Robolectric • src/test • ./gradlew testDevelopDebugUnitTest • Instrumented Test (Emulator/Device) • AndroidJUnitRunner • src/androidTest • ./gradlew connectedDevelopDebugAndroidTest

Slide 11

Slide 11 text

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Ͱ΋ಈ͘ϙʔλϒϧͳ ςετ͕ॻ͚ΔΑ͏ʹ

Slide 12

Slide 12 text

ͦͯ͠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

Slide 13

Slide 13 text

Frictionless Android testing: write once, run everywhere (Google I/O '18)ΑΓ

Slide 14

Slide 14 text

ςετ༻ϢʔςΟϦςΟ • μϛʔσʔλͷੜ੒ • ςετ༻ͷJSONͷϩʔυ • ςετ༻ͷDaggerͷComponent/Module • ...

Slide 15

Slide 15 text

testͱandroidTestͷ྆ํʹஔ͘ͷʁ • γϯϘϦοΫϦϯΫʁ • ίʔυڞ༗ • Sharing code between unit tests and instrumentation tests on Android • src/sharedTest

Slide 16

Slide 16 text

ςετͰͷίʔυڞ༗ 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 } }

Slide 17

Slide 17 text

ςετͰͷίʔυڞ༗ • ςετίʔυ΋ϙʔλϒϧʹͳͬͨ • ςετίʔυࣗମ΋src/sharedTestʹஔ͚͹JVMɾσόΠ εʢΤϛϡϨʔλʣͷ྆ํͰςετͰ͖Δ • Project NitrogenͷઌऔΓʂ

Slide 18

Slide 18 text

Spek

Slide 19

Slide 19 text

Spek • Spek Framework • spekframework/spek: A specification framework for Kotlin • BDDελΠϧͷςετϑϨʔϜϫʔΫ • JUnit 5ϕʔε • 1.xͱ2.x

Slide 20

Slide 20 text

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)) } } } })

Slide 21

Slide 21 text

Spek 1.x • JUnit 4ͷςετϥϯφʔϕʔεͰಈ͔͢ํ๏΋Ҋ಺͞Ε͍ͯ Δ: https://spekframework.github.io/spek/docs/latest/ #setting-up-legacy • @RunWith(JUnitPlatform::class) • @RunWith(AndroidJUnit4::class)ͱผͷςετϥϯφʔʹ ͳΔͷͰɺRobolectricͱҰॹʹ࢖͑ͳ͍

Slide 22

Slide 22 text

Spek 1.x • https://spekframework.github.io/spek/docs/latest/ #_android Android integration tests is currently not supported !

Slide 23

Slide 23 text

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Ͱ͸ݫͦ͠͏ʁ

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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].

Slide 26

Slide 26 text

! Happy Testing!!

Slide 27

Slide 27 text

Thank you