I have the following ADT:
sealed trait TestAdt
case class First(i: Int) extends TestAdt
case class Second(j: String) extends TestAdt
case class Third(k: Long) extends TestAdt
I have a function using TestAdt with the following implementation:
def foo(testAdt: TestAdt): Int = testAdt match {
case f: First => fooFirst(f)
case j: Second => fooSecond(j)
case k: Third => fooThird(k)
}
private def fooFirst(firstAdt: First): Int = //...
private def fooSecond(secondAdt: Second): Int = //...
private def fooThird(thirdAdt: Third): Int = //...
I wrote tests on all fooFirst, fooSecond and fooThird functions as follows:
class FooFirstTest extends AnyFunSuite with Matchers {
//test cases
}
class FooSecondTest extends AnyFunSuite with Matchers {
//test cases
}
class FooThirdTest extends AnyFunSuite with Matchers {
//test cases
}
Now I'd like to test the function foo itself so it seems naturally to just reuse test cases that were implemented for each of the branches separately: FooFirstTest, FooSecondTest and FooThirdTest. For example FooFirstTest covers some test case for the function fooFirst, so the case is hold for the function foo as well.
THE QUESTION: How to reuse tests FooFirstTest, FooSecondTest and FooThirdTest for functions fooFirst, fooSecond and fooThird correspondingly to write tests for the function foo?
class FooTest extends AnyFunSuite with Matchers {
//How to apply FooFirstTest, FooSecondTest, FooThirdTest here?
}
Aucun commentaire:
Enregistrer un commentaire