Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 686
pr1001 Avatar asked Feb 03 '23 05:02

pr1001


1 Answers

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?

like image 195
Chee Seng Avatar answered Feb 16 '23 03:02

Chee Seng