Skip to content

Instantly share code, notes, and snippets.

@rossharper
Created February 20, 2016 21:51
Show Gist options
  • Save rossharper/8f6c3c169b6b5c23e12c to your computer and use it in GitHub Desktop.
Save rossharper/8f6c3c169b6b5c23e12c to your computer and use it in GitHub Desktop.
Parameterized JUnit4 test example in Kotlin
@RunWith(Parameterized::class)
class KotlinTest(val paramOne: Int, val paramTwo: String) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data() : Collection<Array<Any>> {
return listOf(
arrayOf(1, "I"), // First test: (paramOne = 1, paramTwo = "I")
arrayOf(1999, "MCMXCIX") // Second test: (paramOne = 1999, paramTwo = "MCMXCIX")
)
}
}
@Test
fun shouldReturnExpectedRomanForArabic() {
assertThat(RomanNumeralGenerator().arabicToRoman(paramOne), equalTo(paramTwo));
}
}
@rossbeazley
Copy link

holly crap, stumbled across this ;)
👋

@MamboBryan
Copy link

holly crap, stumbled across this ;) 👋

holly molly, came across this 😉

@khaledaboulezz
Copy link

Thanks, but i have a question here

After using the same code, the test runs twice with the same parameter

Any ideas how to prevent that from happening?

@rishikhaneja
Copy link

rishikhaneja commented May 13, 2024

Thanks for this snippet 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment