jeudi 19 avril 2018

Implementing factory in Scalatest

I have the following trait:

trait TraitToTest{
    def doSome(): Unit
}

and some implementations

class Impl1 extends logName
class Impl2 extends logName
class Impl3 extends logName
//...

I have some general contracts for TraitToTest each implementation has to adhere to. I can describe the contract as follows:

class TraitTest extends FunSpec with Matchers{

   describe("TraitTest general contracts"){
       it("should test contract 1"){
           val impl = //some impl of TraitToTest
           //the test
       }
   }
}

The problem is I don't want to duplicate the TraitToTest general contracts for each implementation of TraitToTest. I just want to supply the implementation instance as a sort of factory or so...

Is it possible to do in Scalatest?

Aucun commentaire:

Enregistrer un commentaire