Submit Search
Upload
Kotlinでテストコードを書く
•
8 likes
•
8,930 views
Shoichi Matsuda
Follow
第3回kotlin勉強会 @ SanSan
Read less
Read more
Technology
Report
Share
Report
Share
1 of 31
Download now
Download to read offline
Recommended
Unit Testing in Kotlin
Unit Testing in Kotlin
Egor Andreevich
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
Antonio Goncalves
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
Anton Arhipov
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
Java objects on steroids
Java objects on steroids
Romain Rochegude
NodeJS Spring style Inversifyjs
NodeJS Spring style Inversifyjs
Mathieu Breton
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
Anton Arhipov
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next Generation
BTI360
Recommended
Unit Testing in Kotlin
Unit Testing in Kotlin
Egor Andreevich
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
Antonio Goncalves
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
Anton Arhipov
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
Java objects on steroids
Java objects on steroids
Romain Rochegude
NodeJS Spring style Inversifyjs
NodeJS Spring style Inversifyjs
Mathieu Breton
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
Anton Arhipov
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next Generation
BTI360
Spock Framework
Spock Framework
Леонид Ставила
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
Ray Ploski
CDI: How do I ?
CDI: How do I ?
Antonio Goncalves
Migrating to JUnit 5
Migrating to JUnit 5
Rafael Winterhalter
Spock: Test Well and Prosper
Spock: Test Well and Prosper
Ken Kousen
Agile Android
Agile Android
Godfrey Nolan
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
Danny Preussler
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and Toothpick
Danny Preussler
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
Anton Arhipov
Spock Framework
Spock Framework
Daniel Kolman
Agile Swift
Agile Swift
Godfrey Nolan
Spock
Spock
Evgeny Borisov
Smarter Testing With Spock
Smarter Testing With Spock
IT Weekend
Martin Anderson - threads v actors
Martin Anderson - threads v actors
bloodredsun
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
Ivan Dolgushin
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski
The Groovy Way of Testing with Spock
The Groovy Way of Testing with Spock
Naresha K
Android Design Patterns
Android Design Patterns
Godfrey Nolan
9.Spring DI_4
9.Spring DI_4
탑크리에듀(구로디지털단지역3번출구 2분거리)
Unit/Integration Testing using Spock
Unit/Integration Testing using Spock
Anuj Aneja
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
Omar Miatello
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
More Related Content
What's hot
Spock Framework
Spock Framework
Леонид Ставила
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
Ray Ploski
CDI: How do I ?
CDI: How do I ?
Antonio Goncalves
Migrating to JUnit 5
Migrating to JUnit 5
Rafael Winterhalter
Spock: Test Well and Prosper
Spock: Test Well and Prosper
Ken Kousen
Agile Android
Agile Android
Godfrey Nolan
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
Danny Preussler
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and Toothpick
Danny Preussler
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
Anton Arhipov
Spock Framework
Spock Framework
Daniel Kolman
Agile Swift
Agile Swift
Godfrey Nolan
Spock
Spock
Evgeny Borisov
Smarter Testing With Spock
Smarter Testing With Spock
IT Weekend
Martin Anderson - threads v actors
Martin Anderson - threads v actors
bloodredsun
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
Ivan Dolgushin
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski
The Groovy Way of Testing with Spock
The Groovy Way of Testing with Spock
Naresha K
Android Design Patterns
Android Design Patterns
Godfrey Nolan
9.Spring DI_4
9.Spring DI_4
탑크리에듀(구로디지털단지역3번출구 2분거리)
Unit/Integration Testing using Spock
Unit/Integration Testing using Spock
Anuj Aneja
What's hot
(20)
Spock Framework
Spock Framework
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
CDI: How do I ?
CDI: How do I ?
Migrating to JUnit 5
Migrating to JUnit 5
Spock: Test Well and Prosper
Spock: Test Well and Prosper
Agile Android
Agile Android
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and Toothpick
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
Spock Framework
Spock Framework
Agile Swift
Agile Swift
Spock
Spock
Smarter Testing With Spock
Smarter Testing With Spock
Martin Anderson - threads v actors
Martin Anderson - threads v actors
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
Tomasz Polanski - Automated mobile testing 2016 - Testing: why, when, how
The Groovy Way of Testing with Spock
The Groovy Way of Testing with Spock
Android Design Patterns
Android Design Patterns
9.Spring DI_4
9.Spring DI_4
Unit/Integration Testing using Spock
Unit/Integration Testing using Spock
Similar to Kotlinでテストコードを書く
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
Omar Miatello
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
Kotlin Generation
Kotlin Generation
Minseo Chayabanjonglerd
Mobile Day - React Native
Mobile Day - React Native
Software Guru
Dependency Injection for Android
Dependency Injection for Android
First Tuesday Bergen
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
First Tuesday Bergen
Why Spring <3 Kotlin
Why Spring <3 Kotlin
VMware Tanzu
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
BOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala apps
Peter Pilgrim
JUnit 5
JUnit 5
Scott Leberknight
Spring Boot
Spring Boot
Jiayun Zhou
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
OOP2017: Containerized End-2-End Testing – automate it!
OOP2017: Containerized End-2-End Testing – automate it!
Tobias Schneck
Junit 5 - Maior e melhor
Junit 5 - Maior e melhor
Tiago de Freitas Lima
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
IT Event
Android Unit Test
Android Unit Test
Phuoc Bui
Nice to meet Kotlin
Nice to meet Kotlin
Jieyi Wu
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentation
SAIL_QU
Similar to Kotlinでテストコードを書く
(20)
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
比XML更好用的Java Annotation
比XML更好用的Java Annotation
Kotlin Generation
Kotlin Generation
Mobile Day - React Native
Mobile Day - React Native
Dependency Injection for Android
Dependency Injection for Android
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Why Spring <3 Kotlin
Why Spring <3 Kotlin
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
BOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala apps
JUnit 5
JUnit 5
Spring Boot
Spring Boot
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
OOP2017: Containerized End-2-End Testing – automate it!
OOP2017: Containerized End-2-End Testing – automate it!
Junit 5 - Maior e melhor
Junit 5 - Maior e melhor
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Android Unit Test
Android Unit Test
Nice to meet Kotlin
Nice to meet Kotlin
Csmr2012 bettenburg presentation
Csmr2012 bettenburg presentation
More from Shoichi Matsuda
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
Shoichi Matsuda
広がりを見せるAndroidプラットフォーム
広がりを見せるAndroidプラットフォーム
Shoichi Matsuda
2015冬から始めるKotlin
2015冬から始めるKotlin
Shoichi Matsuda
Gradleスクリプトを読み解く
Gradleスクリプトを読み解く
Shoichi Matsuda
プログラミング言語は怖くない
プログラミング言語は怖くない
Shoichi Matsuda
TddでFizzBuzzしてみる in Swift
TddでFizzBuzzしてみる in Swift
Shoichi Matsuda
モックライブラリを使ってきちんとユニットテストする #Objective-C
モックライブラリを使ってきちんとユニットテストする #Objective-C
Shoichi Matsuda
テストを書きたいあなたが意識すべきただ一つのこと
テストを書きたいあなたが意識すべきただ一つのこと
Shoichi Matsuda
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
Shoichi Matsuda
More from Shoichi Matsuda
(9)
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
広がりを見せるAndroidプラットフォーム
広がりを見せるAndroidプラットフォーム
2015冬から始めるKotlin
2015冬から始めるKotlin
Gradleスクリプトを読み解く
Gradleスクリプトを読み解く
プログラミング言語は怖くない
プログラミング言語は怖くない
TddでFizzBuzzしてみる in Swift
TddでFizzBuzzしてみる in Swift
モックライブラリを使ってきちんとユニットテストする #Objective-C
モックライブラリを使ってきちんとユニットテストする #Objective-C
テストを書きたいあなたが意識すべきただ一つのこと
テストを書きたいあなたが意識すべきただ一つのこと
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
Recently uploaded
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Maria Levchenko
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Neo4j
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Antenna Manufacturer Coco
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Delhi Call girls
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Khem
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Katpro Technologies
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
HampshireHUG
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
Pixlogix Infotech
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
naman860154
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
wesley chun
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Enterprise Knowledge
Recently uploaded
(20)
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Kotlinでテストコードを書く
1.
2.
3.
4.
5.
6.
7.
8.
android { sourceSets { main.java.srcDirs
+= 'src/main/kotlin' test.java.srcDirs += 'src/test/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' } }
9.
//ExampleUnitTest.java public class ExampleUnitTest
{ @Test public void addition_isCorrect() { assertEquals(4, 2 + 2); } }
10.
//ExampleUnitTest.kt class ExampleUnitTest { @Test fun
addition_isCorrect() { assertEquals(4, 2 + 2) } }
11.
12.
13.
14.
15.
//app/build.gradle dependencies { testCompile 'org.mockito:mockito-core:1.10.19' }
16.
//KotlinSimpleMockitoTest.kt class KotlinSimpleMockitoTest { @Test fun
Context () { val context = Mockito.mock(Context::class.java) Mockito.`when`(context.packageName).thenReturn("shoma2da") val packageName = context.getPackageName(); Assert.assertEquals("shoma2da", packageName); } }
17.
//User.kt class User(val birthYear:Int)
{ fun getAge() = 2016 - birthYear }
18.
//UserTest.kt class UserTest { @Test fun
User () { val user = Mockito.mock(User::class.java) Mockito.`when`(user.getAge()).thenReturn(1) val age = user.getAge() Assert.assertEquals(1, age) } }
19.
//logcat org.mockito.exceptions.base.MockitoException: Cannot mock/spy class
YOUR_PACKAGE.User Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
20.
open
21.
22.
//User.kt open class User(val
birthYear:Int) { open fun getAge() = 2016 - birthYear }
23.
24.
//User.kt interface User { fun
getAge():Int } class UserImpl(val birthYear:Int) : User { override fun getAge() = 2016 - birthYear }
25.
26.
//UserTest.kt @RunWith(PowerMockRunner::class) @PrepareForTest(User::class) class UserTest { @Test fun
User () { val user = PowerMockito.mock(User::class.java) Mockito.`when`(user.getAge()).thenReturn(1) val age = user.getAge() Assert.assertEquals(1, age) } } //build.gradle dependencies { testCompile 'org.powermock:powermock-module-junit4:1.6.2' testCompile 'org.powermock:powermock-api-mockito:1.6.2' }
27.
28.
29.
Download now