lambdas
lambdas

Reputation: 4088

How to disable test suite in ScalaTest

How to disable a test suite, i.e. all tests inside class extending FunSpec?

The only solution I'd found is to replace it with ignore in front of each test, but it is boring to do so with the dozens of tests.

Upvotes: 34

Views: 30853

Answers (6)

sbrk
sbrk

Reputation: 1490

Per scalatest docs, say if you have a test suite like this

describe ("some component") {
  it ("should do something") {
   ...
  }
  it ("should also do something else") {
   ...
  }
}

To disable just a single test, you can use the ignore() method.

describe ("some  component") {
  ignore ("should do something") {
   ...
  }
  ...
}

Upvotes: 8

James Moore
James Moore

Reputation: 9026

Use @DoNotDiscover

From the scaladoc:

import org.scalatest._

@DoNotDiscover
class SetSpec extends FlatSpec {

  "An empty Set" should "have size 0" in {
    assert(Set.empty.size === 0)
  }

  it should "produce NoSuchElementException when head is invoked" in {
    intercept[NoSuchElementException] {
      Set.empty.head
    }
  }
}

Upvotes: 5

Bill Venners
Bill Venners

Reputation: 3669

The easy way to do this in 1.8 is to add a constructor that takes a dummy argument. ScalaTest (and sbt) won't discover the class if it doesn't have a public, no-arg constructor:

class MySuite(ignore: String) extends FunSuite { 
  // ...
}

In 2.0 you'll be able to just write @Ignore on the class:

@Ignore
class MySuite extends FunSuite {
  // ...
}

Upvotes: 44

Mitch Sitin
Mitch Sitin

Reputation: 2035

You can use @Ignore both for distinct tests and the whole suit.

Upvotes: 7

Malte Schwerhoff
Malte Schwerhoff

Reputation: 12852

Tags are one option, but you need to tag each tests accordingly, you cannot exclude complete suits that way. However, as user272735 mentioned, tagging tests is a one time effort.

Another option is defining a master suite and limiting the list of nestedSuites to the suites you would like to run (see the docs). The obvious disadvantage is, that you have to maintain the master test suite, i.e., add newly created test suites to it. You could avoid this by recursing through your folders, creating a list of all test suits that can be found, and subtracting those that you put into a black list. In addition, recursing through your folders already gives you an opportunity the filter out files that match an (externally) given criterion.

A third option - albeit more hacky - is to change the package to which the suites you want to black list belong. You can then use a test runner to only run suits included in certain packages. Read more in the docs, section "Specifying 'members-only' and 'wildcard' Suite paths".

Upvotes: 2

user272735
user272735

Reputation: 10648

Tag the troublesome tests and then exclude or include tests based on the tag.

Tagging is a one time effort.

Upvotes: 3

Related Questions