简体   繁体   中英

Excluding a ScalaTest test when calling my tests from within sbt

I want to write a test that calls a remote server and validates the response because the server may change (it's not under my control). To do this I figure I'd give it a tag ( RemoteTest ) and then exclude it when calling the runner :

sbt> test-only * -- -l RemoteTest

However, when doing this all my tests are run, including RemoteTest . How do I call the runner from within sbt so that it is excluded?

If you have the following:-

package com.test

import org.scalatest.FlatSpec
import org.scalatest.Tag

object SlowTest extends Tag("com.mycompany.tags.SlowTest")
object DbTest extends Tag("com.mycompany.tags.DbTest")

class TestSuite extends FlatSpec {

  "The Scala language" must "add correctly" taggedAs(SlowTest) in {
      val sum = 1 + 1
      assert(sum === 2)
    }

  it must "subtract correctly" taggedAs(SlowTest, DbTest) in {
    val diff = 4 - 1
    assert(diff === 3)
  }
}

To exclude DbTest tag, you would do:-

test-only * -- -l com.mycompany.tags.DbTest

Note that you'll need to include the full tag name. If it's still not working for you, would you mind sharing part of source code that's not working?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM