The parameterless execute method has been deprecated and will be removed in a future version of ScalaTest. Please invoke execute with empty parens instead: execute().
The trap method is no longer needed for demos in the REPL, which now abreviates stack traces, and will be removed in a future version of ScalaTest
Trait that can be mixed into a ScalaTest suite to provide mocking support.
Sharing mocks across test cases
Sometimes multiple test cases need to work with the same mocks (and more generally - the same fixtures: files, sockets, database connections, etc.). There are many techniques to avoid duplicating the fixture code across test cases in ScalaTest, but ScalaMock recommends and officially supports these two:
Isolated test cases
If you mix
OneInstancePerTest
trait into aSuite
, each test case will run in its own instance of the suite class and therefore each test will get a fresh copy of the instance variables.This way in the suite scope you can declare instance variables (e.g. mocks) that will be used by multiple test cases and perform common test case setup (e.g. set up some mock expectations). Because each test cases has fresh instance variables different test cases do not interfere with each other.
Fixture contexts
You can also run each test case in separate fixture context. Fixture contexts can be extended and combined and since each test case uses different instance of fixture context test cases do not interfere with each other while they can have shared mocks and expectations.
See org.scalamock for overview documentation.