ScalaTest 105: Adding more tests and a test suite

Problem: You want to add more unit tests and a main test suite to your ScalaTest tests.

Solution

To add more unit tests to your project, just create new test classes. For instance, to add a set of TDD-style tests for the Topping class, just create a ToppingTests class in the src/test/scala/com/acme/pizza directory:

package com.acme.pizza

import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter

class ToppingTests extends FunSuite with BeforeAndAfter {

  // add tests here ...
  test("test topping quantity") (pending)

}

Assuming that you have the Pizza, Topping, and PizzaTests classes installed as described in Writing TDD Tests with ScalaTest, your test output will now look like:

[info] PizzaTests:
[info] - new pizza has zero toppings
[info] - adding one topping
[info] - adding and removing topping
[info] - catching an exception
[info] - test pizza pricing (pending)
[info] ToppingTests:
[info] – test topping quantity (pending)

To continue adding more tests, just add more test classes. Other ScalaTest recipes in this series of articles demonstrate how to control which tests are run.

See Also

ScalaTest does have a concept of “nested suites,” but they aren’t well documented at this time. See this URL for information: