Last active
July 29, 2020 13:42
-
-
Save trietbui85/4171305de0154e43a0e31d30a873a4de to your computer and use it in GitHub Desktop.
Unit test Android custom view with AndroidX Test and Robolectric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mobtiso.test.customview | |
import androidx.test.core.app.ApplicationProvider | |
import com.google.common.truth.Truth.assertThat | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.robolectric.RobolectricTestRunner | |
import org.robolectric.annotation.Config | |
@RunWith(RobolectricTestRunner::class) | |
@Config(sdk = [28]) | |
class CountViewTest { | |
private val context = ApplicationProvider.getApplicationContext<Context>(); | |
private val countView = CountView(context) | |
private val buttonAdd = countView.findViewById<Button>(R.id.buttonAdd) | |
private val textViewValue = countView.findViewById<TextView>(R.id.textView) | |
@Test | |
fun testSetUpIsOk() { | |
assertThat(countView.context).isNotNull() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment