ScalaTest 110: Temporarily disabling unit tests

Problem: When using ScalaTest, you want to temporarily disable one or more tests, presumably until you can get them working again.

Solution

When using BDD-style tests, change it method calls to ignore:

ignore ("A new pizza has zero toppings", DatabaseTest) {
  Given("a new pizza")
  pizza = new Pizza
  Then("the topping count should be zero")
  assert(pizza.getToppings.size == 0)
}

With TDD-style tests, change test method calls to ignore:

ignore ("A new pizza has zero toppings", DatabaseTest) {
  //assert(pizza.getToppings.size === 1)
  expectResult(0) {
    pizza.getToppings.size
  }
}

When you run your tests, the tests you changed to ignore will result in output similar to the following:

[info] - A new pizza has zero toppings !!! IGNORED !!!

When run from the command line using SBT, this output is displayed in a yellow font.

Discussion

Many times when testing your code, you’ll need to temporarily disable some tests until you can get them working again. Changing it and test to ignore is a simple way to change the tests so they’ll be skipped over. The output is a hard-to-miss reminder that the tests are being ignored.

See Also

See these links for more information: