Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.








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でテストコードを書く
Próxima SlideShare
Cargando en…5
×

Kotlinでテストコードを書く

8.479 visualizaciones

Publicado el

第3回kotlin勉強会 @ SanSan

Publicado en: Tecnología
  • 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 ⇐
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • 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 ⇐
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • 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
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/39sFWPG ❶❶❶
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39sFWPG ❶❶❶
       Responder 
    ¿Estás seguro?    No
    Tu mensaje aparecerá aquí

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. 
 


×