• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    Robolectric test base live template
    Last Modify : 01 August, 2019(12:49)
    import android.app.Application import android.content.Context import android.content.res.Resources import androidx.test.core.app.ApplicationProvider import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.mock import org.mockito.MockitoAnnotations import org.robolectric.RobolectricTestRunner import org.robolectric.Shadows import org.robolectric.annotation.Config import org.slf4j.LoggerFactory /** * Created by <a href="mailto:aucd29@hanwha.com">Burke Choi</a> on $DATE$ <p/> */ @RunWith(RobolectricTestRunner::class) class $CLASSNAME$ { $SELECTION$ @Before @Throws(Exception::class) fun setup() { initMock() } @Test //@Config(sdk=[24], manifest = "src/main/AndroidManifest.xml") fun test() { } //////////////////////////////////////////////////////////////////////////////////// // // MOCK // //////////////////////////////////////////////////////////////////////////////////// companion object { private val mLog = LoggerFactory.getLogger($CLASSNAME$::class.java) } private fun initMock() { MockitoAnnotations.initMocks(this) // shadowApp.grantPermissions(android.Manifest.permission.ACCESS_FINE_LOCATION) } // https://stackoverflow.com/questions/13684094/how-can-we-access-context-of-an-application-in-robolectric private val app = ApplicationProvider.getApplicationContext<MainApp>() // https://stackoverflow.com/questions/35031301/android-robolectric-unit-test-for-marshmallow-permissionhelper private val shadowApp = Shadows.shadowOf(app) }

    Comment


    입력하3 1591026686



    Locations of visitors to this page