Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScalaTest on sbt not running any tests

I am trying to run my tests with: sbt and then test.

My build.sbt looks like this

lazy val scalatest =  "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
lazy val root = (project in file(".")).
settings(
    name := "highlight2pdf",
    version := "0.1",
    scalaVersion := "2.11.6",
    libraryDependencies +=  scalatest
)

And i just put the example test on test/scala

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

    class ExampleSpec extends FlatSpec with Matchers {

        "A Stack" should "pop values in last-in-first-out order" in {
            val stack = new Stack[Int]
            stack.push(1)
            stack.push(2)
            stack.pop() should be (2)
            stack.pop() should be (1)
        }

        it should "throw NoSuchElementException if an empty stack is popped" in {
            val emptyStack = new Stack[Int]
            a [NoSuchElementException] should be thrownBy {
                emptyStack.pop()
            } 
        }
    }

Still it always show:

[info] No tests were executed.

Any thoughts on why it's not working?

like image 354
FabioCosta Avatar asked Apr 30 '15 15:04

FabioCosta


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

The directory structure isn't the correct convention for sbt to find ExampleSpec.scala by default.

├── built.sbt
├── src
│   └── test
│       └── scala
│           ├── ExampleSpec.scala

Change it to the structure above and run sbt test in the top level directory and it should work. Likewise, scala source would go in src/main/scala and would get compiled.

> test
[info] Compiling 1 Scala source to /tmp/TestsWontRun/target/scala-2.11/test-classes...
[info] ExampleSpec:
[info] A Stack
[info] - should pop values in last-in-first-out order
[info] - should throw NoSuchElementException if an empty stack is popped
[info] Run completed in 289 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 7 s, completed Apr 30, 2015 8:54:30 AM
like image 148
Brian Avatar answered Sep 20 '22 16:09

Brian