Skip to content

Instantly share code, notes, and snippets.

@harmittaa
Created October 29, 2019 16:15
Show Gist options
  • Save harmittaa/7a1d7334578a65c22f7aaaca1a423d22 to your computer and use it in GitHub Desktop.
Save harmittaa/7a1d7334578a65c22f7aaaca1a423d22 to your computer and use it in GitHub Desktop.
@RunWith(ParameterizedRobolectricTestRunner::class)
@Config(sdk = [27])
// parameters declared in the params() are injected through the constructor to the test class
class ExampleUnitTest(private val param: Int) {
@Test
fun addition_isCorrect() {
// parameter use in a test
assertEquals(param * 2, param + param)
}
companion object {
@JvmStatic
// name argument is optional, it will show up on the test results
@ParameterizedRobolectricTestRunner.Parameters(name = "Input: {0}")
// parameters are provided as arrays, allowing more than one parameter
fun params() = listOf(
arrayOf(1),
arrayOf(2),
arrayOf(3),
arrayOf(4)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment