How to disable test suite in ScalaTest
Asked Answered
H

6

32

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.

Hasidism answered 17/7, 2012 at 4:30 Comment(1)
Whatever you do, don't comment it out :)United
F
43

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 {
  // ...
}
Flipper answered 18/7, 2012 at 3:4 Comment(1)
I tried this but it had no affect I am using scala 2.10.2, please help me out. @BillVennersMadeleinemadelena
J
7

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

Jehovah answered 3/7, 2015 at 17:12 Comment(0)
S
7

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") {
   ...
  }
  ...
}
Stumble answered 26/10, 2020 at 19:59 Comment(0)
O
5

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
    }
  }
}
Ovida answered 18/5, 2020 at 16:40 Comment(1)
DoNotDiscover works better than Ignore when you have test (class) constructor code that may fail at runtime.Armada
F
3

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

Tagging is a one time effort.

Foreyard answered 17/7, 2012 at 5:53 Comment(0)
C
2

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".

Carlsbad answered 17/7, 2012 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.