paulbutcher/ScalaMock — Issue #5: ScalaMock does not work with ScalaTest's TestNG/JUnit Support Traits
Author: peregin55
Created: 2012-02-02 19:58:19+00:00
State: open

ScalaMock currently does not integrate with ScalaTest's `TestNGSuite` or `JUnitSuite` traits. I am using ScalaMock_2.9.1-2.2 and ScalaTest_2.9.1-1.6.1.

Here's a sample test, using `TestNGSuite`:

import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory
import org.scalatest.testng.TestNGSuite

class ScalaMockTestNG extends TestNGSuite with MockFactory with ProxyMockFactory

The following error is produced:

error: overriding method runTests in trait TestNGSuite of type (testName: Option[String], reporter: org.scalatest.Reporter, stopper: org.scalatest.Stopper, filter: org.scalatest.Filter, configMap: Map[String,Any], distributor: Option[org.scalatest.Distributor], tracker: org.scalatest.Tracker)Unit;
method runTests in trait MockFactory of type (testName: Option[String], reporter: org.scalatest.Reporter, stopper: org.scalatest.Stopper, filter: org.scalatest.Filter, configMap: Map[String,Any], distributor: Option[org.scalatest.Distributor], tracker: org.scalatest.Tracker)Unit cannot override final member;
other members with override errors are: runTest
class ScalaMockTestNG extends TestNGSuite with MockFactory with ProxyMockFactory
^
one error found

It appears that ScalaTest's `TestNGSuite` does not use the `runTest` method.

From the ScalaTest `TestNGSuite` source (http://code.google.com/p/scalatest/source/browse/tags/release-1.6.1/src/main/scala/org/scalatest/testng/TestNGSuite.scala ):

The main purpose of this method implementation is to render a compiler error an attempt
to mix in a trait that overrides runTests. Because this
trait does not actually use runTests, the attempt to mix
in behavior would very likely not work.