Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How_to_Test_Server-side_Kotlin.pdf
Search
Taro Nagasawa
September 11, 2018
Programming
1
470
How_to_Test_Server-side_Kotlin.pdf
Kotlin Fest 2018 わいわい報告会 (
https://connpass.com/event/100752/
) で発表したスライドです
Taro Nagasawa
September 11, 2018
Tweet
Share
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
530
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.2k
#Ubie 狂気の認知施策と選考設計
ntaro
13
13k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.1k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.4k
Kotlinでサーバサイドを始めよう!
ntaro
1
950
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2.6k
Kotlin Contracts #m3kt
ntaro
4
3.9k
Kotlin Fest 2018 - Opening session
ntaro
0
4.2k
Other Decks in Programming
See All in Programming
GAEログのコスト削減
mot_techtalk
0
120
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
150
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
330
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
1
210
color-scheme: light dark; を完全に理解する
uhyo
7
480
Conform を推す - Advocating for Conform
mizoguchicoji
3
710
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
280
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
620
楽しく向き合う例外対応
okutsu
0
570
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
1
310
バッチを作らなきゃとなったときに考えること
irof
2
480
ARA Ansible for the teams
kksat
0
170
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
For a Future-Friendly Web
brad_frost
176
9.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
How STYLIGHT went responsive
nonsquared
98
5.4k
Six Lessons from altMBA
skipperchong
27
3.6k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
250
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Language of Interfaces
destraynor
156
24k
Transcript
How to Test Server-side Kotlin 2018-09-11 長澤太郎
長澤太郎 • @ngsw_taro • Ubie株式会社 ソフトウェアエンジニア • 日本Kotlinユーザグループ代表
Redesign Medical Care
Kontributer しらじさん JOIN!!!!
お疲れ様でした! https://photos.google.com/share/AF1QipMux-IXIIBpf2Rr_HwWtQu5pICYJlVCS9yzDmdVbEm0Gajya5D9-pS0A__jXksrAg?key=N0dDZ1hWd HNFVTFodHlpN1BiaC1laXpqQXJkN1Z3 より引用
How to Test Server-side Kotlin エムスリー 前原さん、鈴木さん https://photos.google.com/share/AF1QipMux-IXIIBpf2Rr_HwWtQu5pICYJlVCS9yzDmdVbEm0Gajya5D9-pS0A__jXksrAg?key=N0dDZ1hWd HNFVTFodHlpN1BiaC1laXpqQXJkN1Z3 より引用
How to Test Server-side Kotlin 編
UbieではKotlin x SpringでAPI開発してます
テスト関係のフレームワークやライブラリ • JUnit5 - Jupiter • Spring Test - WebTestClient
• AssertJ • MockK • DbSetup-kotlin
JUnit5 class FooTest { @Nested inner class fooMethod { @Test
fun `should throw exception`() { assertThrows<MyException>() { Foo().foo() } } } }
class FooTest { @Nested inner class fooMethod { @Test fun
`should throw exception`() { assertThrows<MyException>() { Foo().foo() } } } } JUnit5
JUnit5 class FooTest { @Nested inner class fooMethod { @Test
fun `should throw exception`() { assertThrows<MyException>() { Foo().foo() } } } }
AssertJ val got = sut.findUser(id) assertThat(got).isNotNull assertThat(got?.name).isEqualTo("ほげ")
AssertJ val got = sut.findUser(id) assertThat(got).isNotNull assertThat(got?.name).isEqualTo("ほげ") Kotlin 1.3 Contractsで実現か!?
MockK interface UserRepository { suspend fun findUser(id: Long): User? }
val userRepo = mockk<UserRepository>() every { userRepo.findUser(1) } returns user
MockK interface UserRepository { suspend fun findUser(id: Long): User? }
val userRepo = mockk<UserRepository>() every { userRepo.findUser(1) } returns user coEvery { userRepo.findUser(1) } returns user
WebTestClient - expectBodyメソッド webTestClient.get() .exchange() .expectBody(MyApiBody::class.java) .isEqualTo<Nothing>(expectedBody) NullPointerException が出る!
WebTestClient - expectBody拡張関数 webTestClient.get() .exchange() .expectBody<MyApiBody>() .isEqualTo<Nothing>(expectedBody) import org.springframework.test.web.reactive.server.expectBody いける!
WebTestClient - expectBody拡張関数 webTestClient.get() .exchange() .expectBody<MyApiBody>() .isEqualTo<Nothing>(expectedBody) import org.springframework.test.web.reactive.server.expectBody いける!
が、サジェストされない
Pluginのバグ(issueあった)
しらじさん修正プルリク!!!神!!!!
リリースされるのは 1.3.20 乞うご期待