我有一个密封的特征,我想为其编写测试。但是,不可能在测试类中创建具有此密封特性的对象。在这种情况下如何进行测试。
Myclass.scala
sealed trait BaseTrait{
def myFunct = //an implemented function
}
case class SecondClass extends BaseTrait {
// This class I can test
// ...
}
MyclassTest.Scala
class MyclassTest extends WordSpec with MustMatchers{
//Here I want to write a test case for the function within the sealed trait
}
我正在使用 Play Framework 2.3.6 和 Scala 开发一个项目,并使用 ScalaTestPlus 进行测试。
最佳答案
这可能是不可能的。最好的办法是实例化扩展该特征的最简单的类并对其进行测试。
关于testing - 在 Scala 中为密封特性创建测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27528143/