Skip to content

Instantly share code, notes, and snippets.

@trietbui85
Last active July 29, 2020 13:42
Show Gist options
  • Save trietbui85/4171305de0154e43a0e31d30a873a4de to your computer and use it in GitHub Desktop.
Save trietbui85/4171305de0154e43a0e31d30a873a4de to your computer and use it in GitHub Desktop.
Unit test Android custom view with AndroidX Test and Robolectric
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