O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test fixtures

Test fixture is a collection of classes, other libraries, and artifacts. These can be files, sockets, database connections, and so on, that are required for testing. Clean code principles dictate that we reuse these fixtures across tests and make them as abstract as possible. For example, if two tests require speaking to a database, then it would be obvious to reuse the same database connection code for both. It is important to try and avoid duplicating the fixture code across those tests. The more code duplication you have in your tests, the greater drag the tests will have on refactoring the actual.

These are the recommended techniques for reusing the code in ScalaTest:

  • Refactor using Scala
  • Override withFixture
  • Mixin a before-and-after ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required