ScalaTest: Simply Productive

Latest Release - ScalaTest and Scalactic 3.2.19!

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

class ExampleSpec extends AnyFlatSpec with should.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()
    } 
  }
}

ScalaTest is the most flexible and most popular testing tool in the Scala ecosystem. With ScalaTest, you can test Scala, Scala.js (JavaScript), Scala Native, Dotty (Scala 3), and Java code. By offering deep integration with tools such as JUnit, TestNG, Ant, Maven, sbt, ScalaCheck, JMock, EasyMock, Mockito, ScalaMock, Selenium, Eclipse, NetBeans, and IntelliJ, ScalaTest makes it easy to take your testing to a higher, more productive level in new or existing Scala, Scala.js, or Java projects.

Like the Scala language on which it is built, ScalaTest is designed to grow with the demands of its users: You can easily extend and compose ScalaTest's core components to address just about any special requirements you may have. As a result, ScalaTest can scale to projects of all sizes, from an individual exploring a new idea to large teams collaborating on mission-critical software.

One way ScalaTest scales down is that despite its rich feature set, ScalaTest is easy to get into. Building on what you already know from experience with other test frameworks, you can become productive with ScalaTest very quickly.

To maximize your productivity, ScalaTest uses its own extension points to support several styles of testing out of the box. You can select whatever style best fits your team's experience and culture. For instance, the above example uses FlatSpec, a good choice for teams wishing to move from XUnit to BDD. When you run it, you get an informal specification of the software being tested:

$ CLASSPATH=scalatest-app_3-3.2.19.jar:scala-xml_3-2.1.0.jar
$ scala -cp $CLASSPATH org.scalatest.run ExampleSpec
Discovery starting.
Discovery completed in 21 milliseconds.
Run starting. Expected test count is: 2
ExampleSpec:
A Stack
- should pop values in last-in-first-out order
- should throw NoSuchElementException if an empty stack is popped
Run completed in 76 milliseconds.
Total number of tests run: 2
Suites: completed 1, aborted 0
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
All tests passed.

ScalaTest does not try to impose a testing philosophy on you, but rather is designed from the philosophy that the tool should get out of your way and let you work the way you find most productive. If FlatSpec doesn't meet your team's needs, that's not a problem. ScalaTest has several other styles to choose from.

In short, ScalaTest is a workbench providing many small, focused tools you can compose together to solve the problems you face today, yet grow with you as your needs change tomorrow.

Why not give it a try? Visit the Quick Start page.

ScalaTest is brought to you by Bill Venners and Artima.
ScalaTest is free, open-source software released under the Apache 2.0 license.

If your company loves ScalaTest, please consider sponsoring the project.

Copyright © 2009-2024 Artima, Inc. All Rights Reserved.

artima