Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
How_to_Test_Server-side_Kotlin.pdf
Taro Nagasawa
September 11, 2018
Programming
1
320
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
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
1.7k
#Ubie 狂気の認知施策と選考設計
ntaro
12
10k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
860
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
2.9k
Kotlinでサーバサイドを始めよう!
ntaro
1
730
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2k
Kotlin Contracts #m3kt
ntaro
4
2.9k
Kotlin Fest 2018 - Opening session
ntaro
0
4.1k
Spring Fu on GraalVM
ntaro
0
2k
Other Decks in Programming
See All in Programming
2023年にクル(かもしれない)通信ミドルウェア技術(仮)
s_hosoai
0
220
LIFFで動く割り勘アプリTATEKAをリリースしてみた話
inoue2002
0
270
xarray-Datatree: Hierarchical Data Structures for Multi-Model Science
tomnicholas
0
240
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
240
SwiftPMのPlugin入門 / introduction_to_swiftpm_plugin
uhooi
2
110
Rust、何もわからない...#6発表資料
ryu19
0
170
TokyoR#103_DataProcessing
kilometer
0
550
Circuit⚡
monaapk
0
200
Listかもしれない
irof
1
290
OIDC仕様に準拠した Makuake ID連携基盤構築の裏側
ymtdzzz
0
610
Remote SSHで行うVS Codeリモートホスト開発とトラブルシューティング
smt7174
1
520
Remix + Cloudflare Pages + D1 で ポケモン SV のレンタルチームを検索できるアプリを作ってみた
kuroppe1819
4
1.4k
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
108
5.9k
jQuery: Nuts, Bolts and Bling
dougneiner
57
6.6k
How to train your dragon (web standard)
notwaldorf
66
4.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
850
Scaling GitHub
holman
453
140k
Designing Experiences People Love
moore
130
22k
KATA
mclloyd
12
9.7k
No one is an island. Learnings from fostering a developers community.
thoeni
12
1.5k
Infographics Made Easy
chrislema
235
17k
Streamline your AJAX requests with AmplifyJS and jQuery
dougneiner
128
8.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
226
130k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
349
27k
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 乞うご期待