Creating Test for a sealed trait in scala

1.7k Views Asked by At

I have a sealed trait for which I want to write tests. However it is not possible to create an object of this sealed trait within the test class. How is it possible to test in such case.

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

}

I am working on a project with Play Framework 2.3.6 and Scala and using ScalaTestPlus for testing.

1

There are 1 best solutions below

0
On

That may not be possible. Your best bet is to instantiate the simplest class that extends that trait and test it.