Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sbt won't run ScalaTest tests

I'm running Scala 2.10.3 and sbt 0.13.5, and loosely following Twitter's scala sbt tutorial I've run into a minor issue. The unit test won't run at all.

my build.sbt:

libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.7" % "test"

my test class:

package com.twitter.sample

import collection.mutable.Stack
import org.scalatest._

object SimpleParserSpec extends FlatSpec with Matchers {
  "SimpleParser" should "work with basic tweet" in {
    val parser = new SimpleParser
    val tweet = """{"id":1, "text":"foo"}"""
    parser.parse(tweet) match {
      case Some(parsed) => {
        parsed.text should be ("foo")
        parsed.id should be (1)
      }
      case _ => fail("didn't parse tweet")
    }
  }
}

and this is the output of running sbt test in the project folder:

[info] Loading global plugins from C:\Users\Slench\.sbt\0.13\plugins
[info] Set current project to twitter-sbt (in build file:/C:/Users/Slench/Desktop/twitter-sbt/)
[info] Run completed in 36 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 0 s, completed 05-06-2014 20:19:11

I'm not sure what's going wrong, all the files are in the correct folders, everything compiles without error or warnings, yet it won't run my test... Any help?

like image 493
Electric Coffee Avatar asked Jun 05 '14 18:06

Electric Coffee


People also ask

What is ScalaTest sbt?

ScalaTest is one of the main testing libraries for Scala projects, and in this lesson you'll see how to create a Scala project that uses ScalaTest. You'll also be able to compile, test, and run the project with sbt.

Does sbt run tests in parallel?

sbt maps each test class to a task. sbt runs tasks in parallel and within the same JVM by default.


1 Answers

Change your SimpleParserSpec from object to class and it should work.

In particular change the line

//bad
object SimpleParserSpec extends FlatSpec with Matchers

to

//good
class SimpleParserSpec extends FlatSpec with Matchers
like image 192
lpiepiora Avatar answered Oct 13 '22 17:10

lpiepiora