Friday, January 24, 2020

ScalaTest in sbt: is there a way to run a single test without tags?

ScalaTest in sbt: is there a way to run a single test without tags?

a single test can be ran by running, in sbt, 
testOnly *class -- -n Tag
to run only the tests whose name includes the substring "foo".
testOnly *MySuite -- -z foo
For exact match rather than substring, use -t instead of -z.

Updating a mutable map counter value


val symTab = collection.mutable.HashMap[String, Int]()
def update0(s: String): Unit = {
  if (symTab.contains(s)) {
    symTab(s) = symTab(s) + 1
  }
  else {
    symTab(s) = 1
  }
}

// Do this instead
def update1(s: String): Unit = symTab(s) = symTab.getOrElse(s, 0) + 1

scala> update1("x")

scala> symTab("x")
res2: Int = 1

scala> update1("x")

scala> symTab("x")

res4: Int = 2