LoginSignup
17
15

More than 5 years have passed since last update.

KotlinでAndroid Test Case書くときのテンプレート

Posted at

ただのメモ。

テンプレートの記述方法とかは KotlinでFragment書くときのテンプレート を参照

android_test_case.png

下記を File and Code Templates にコピペする。

AndroidTestCase.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import android.test.AndroidTestCase
import org.junit
import org.junit.runner.RunWith
import kotlin.test.*

#end
#parse("File Header.java")
RunWith(AndroidJUnit4::class)
public class ${NAME} {
    junit.Before
    fun setup() {}

    junit.After
    fun teardown() {}

    junit.Test
    fun example() {
        assertEquals("TODO: write test", "")
    }

    fun getContext() : Context {
        return InstrumentationRegistry.getTargetContext()
    }
}
17
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
15