Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.








android {
sourceSets {

main.java.srcDirs += 'src/main/kotlin'

test.java.srcDirs += 'src/test/kotlin'

androidTest.java.s...
//ExampleUnitTest.java
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
//ExampleUnitTest.kt
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
//app/build.gradle
dependencies {
testCompile 'org.mockito:mockito-core:1.10.19'
}
//KotlinSimpleMockitoTest.kt
class KotlinSimpleMockitoTest {
@Test
fun Context () {
val context = Mockito.mock(Context::cl...
//User.kt
class User(val birthYear:Int) {
fun getAge() = 2016 - birthYear
}
//UserTest.kt
class UserTest {
@Test
fun User () {
val user = Mockito.mock(User::class.java)
Mockito.`when`(user.getAge())...
//logcat
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class YOUR_PACKAGE.User
Mockito cannot mock/spy fol...
open


//User.kt
open class User(val birthYear:Int) {
open fun getAge() = 2016 - birthYear
}
//User.kt
interface User {
fun getAge():Int
}
class UserImpl(val birthYear:Int) : User {
override fun getAge() = 2016 - bi...
//UserTest.kt
@RunWith(PowerMockRunner::class)
@PrepareForTest(User::class)
class UserTest {
@Test
fun User () {
val user ...




Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Kotlinでテストコードを書く
Nächste SlideShare
Wird geladen in …5
×

Kotlinでテストコードを書く

8.482 Aufrufe

Veröffentlicht am

第3回kotlin勉強会 @ SanSan

Veröffentlicht in: Technologie
  • A professional Paper writing services can alleviate your stress in writing a successful paper and take the pressure off you to hand it in on time. Check out, please ⇒ www.HelpWriting.net ⇐
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Writing good research paper is quite easy and very difficult simultaneously. It depends on the individual skill set also. You can get help from research paper writing. Check out, please ⇒ www.WritePaper.info ⇐
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/39sFWPG ❶❶❶
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39sFWPG ❶❶❶
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier

Kotlinでテストコードを書く

  1. 1. 
 

  2. 2. 
 

  3. 3. android { sourceSets {
 main.java.srcDirs += 'src/main/kotlin'
 test.java.srcDirs += 'src/test/kotlin'
 androidTest.java.srcDirs += 'src/androidTest/kotlin'
 }
 }
  4. 4. //ExampleUnitTest.java public class ExampleUnitTest { @Test public void addition_isCorrect() { assertEquals(4, 2 + 2); } }
  5. 5. //ExampleUnitTest.kt class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
  6. 6. //app/build.gradle dependencies { testCompile 'org.mockito:mockito-core:1.10.19' }
  7. 7. //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); } }
  8. 8. //User.kt class User(val birthYear:Int) { fun getAge() = 2016 - birthYear }
  9. 9. //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) } }
  10. 10. //logcat org.mockito.exceptions.base.MockitoException: Cannot mock/spy class YOUR_PACKAGE.User Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
  11. 11. open 

  12. 12. //User.kt open class User(val birthYear:Int) { open fun getAge() = 2016 - birthYear }
  13. 13. //User.kt interface User { fun getAge():Int } class UserImpl(val birthYear:Int) : User { override fun getAge() = 2016 - birthYear }
  14. 14. //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' }
  15. 15. 
 


×