Answer the question
In order to leave comments, you need to log in
JUnit 4, testable functions need to be written in a test class?
If I'm testing functions, do they need to be rewritten in the class under test, like in this example?
@RunWith(Parameterized::class)
class MyPresenterTest(var s1:String,
var s2:String,
var s3:String,
var sResult:String) {
companion object{
@JvmStatic
@Parameterized.Parameters
fun testParams() = arrayOf(arrayOf("1","+","1","2"))
}
fun getResult():String {
return if (s1.isNotEmpty()&& s2.isNotEmpty()&&s3.isNotEmpty())
{
when(s2){
"+"->{s1.toInt()+s3.toInt()}
"-"->{s1.toInt()-s3.toInt()}
"*"->{s1.toInt()*s3.toInt()}
"/"->{s1.toInt()/s3.toInt()}
else ->{0}
}.toString()
}
else
{
return "0"
}
}
@Test
fun getResultTest() {
val result=getResult()
assertEquals(result,sResult)
}
}
Answer the question
In order to leave comments, you need to log in
Tests check the code to be executed. There is no point in testing code that won't run.
Tested functions do not need to be written in a test class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question