【问题标题】:Creating Test for a sealed trait in scala在scala中为密封特征创建测试
【发布时间】:2016-02-06 09:36:35
【问题描述】:

我有一个密封的特征,我想为其编写测试。但是,不可能在测试类中创建此密封特征的对象。在这种情况下如何进行测试。

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 playframework-2.0 scalatest traits sealed


    【解决方案1】:

    这可能是不可能的。最好的办法是实例化扩展该特征的最简单的类并对其进行测试。

    【讨论】:

      猜你喜欢
      • 2015-05-26
      • 2015-09-17
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      相关资源
      最近更新 更多