ScalaTest 107: How to mark a test as ‘pending’

Problem: You want to note that a ScalaTest unit test needs to be created, but you’re not ready to write it yet.

Solution

Instead of supplying the body of a test method, mark the test as pending. In the ScalaTest TDD style, create a pending test like this:

test ("should allow removal of toppings") (pending)

In the ScalaTest BDD style, create a pending test like this:

it("should allow removal of toppings") (pending)

When your tests are run, pending tests will be printed like this:

[info] - should allow addition of toppings (pending)

Discussion

When tests are run at the command line with SBT, pending lines are printed in a yellow(ish) color.

Marking tests as pending helps support the TDD style, and it’s a convenient way of saying, “I need to write this test and implement the code behind it, but I haven’t gotten there yet.”

See Also

The Scala Cookbook

This tutorial is sponsored by the Scala Cookbook, which I wrote, and was published by O’Reilly in late 2013:

You can find the Scala Cookbook at these locations:

I hope it has been helpful. All the best, Al.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.