ScalaTest User Guide Getting started Selecting testing styles Defining base classes Writing your first test Using assertions Tagging your tests Running your tests Sharing fixtures Sharing tests Using matchers Testing with mock objects Property-based testing Asynchronous testing Using Scala-js Using Inside Using OptionValues Using EitherValues Using PartialFunctionValues Using PrivateMethodTester Using WrapWith Philosophy and design Migrating to 3.0 |
Defining base classes for your projectScalaTest is a testing toolkit: it consists of focused, lightweight traits that you can mix together to solve the problem at hand. This approach minimizes the potential for naming and implicit conflicts and helps speed compiles.
Instead of duplicating code by mixing the same traits together repeatedly, we recommend you create abstract base
classes for your project that mix together the features you use the most. For example, you might create
a package com.mycompany.myproject import org.scalatest._ import flatspec._ import matchers._ abstract class UnitSpec extends AnyFlatSpec with should.Matchers with OptionValues with Inside with Inspectors You can then write unit tests for your project using the custom base class, like this: package com.mycompany.myproject import org.scalatest._ class MySpec extends UnitSpec { // Your tests here }
Most projects end up with multiple base classes, each focused on different kinds of tests. You might have a base class for integration tests
that require a database (perhaps named
Note that in the rest of the user guide, we don't extend With that, it is time to write your first test. |
ScalaTest is brought to you by Bill Venners and Artima.
ScalaTest is free, open-source software
released under the Apache
2.0 license.
If your company loves ScalaTest, please consider sponsoring the project.
Copyright © 2009-2025 Artima, Inc. All Rights Reserved.