CINXE.COM
ScalaTest
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>ScalaTest</title> <link rel="Stylesheet" href="/assets/stylesheets/main.css" type="text/css" media="screen"/> <link rel="stylesheet" type="text/css" href="/assets/stylesheets/print.css" media="print" /> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-NJWCS90VG5"></script> <script defer src='/assets/javascripts/gtag.js'></script> </head> <body> <div class="Container"> <!-- Top of scalatest.org 660 x 60 [async] --> <script id="adsArtimaScript" type="text/javascript" src="https://www.artima.com/assets/javascripts/4ca150665e51d0b1c3890ca1b891c507-ads.js?product=ScalaTest"></script> <div id="Header"> <div id="Nav"> <span><em>Home</em></span> | <a href="/quick_start">Quick Start</a> | <a href="/install">Install</a> | <a href="/user_guide">User Guide</a> | <a href="/at_a_glance">At A Glance</a> | <a href="/scaladoc">Scaladoc</a> | <a href="/supersafe">SuperSafe</a> | <a href="/plus">Plus</a> | <!-- <a href="/videos">Videos</a> | --> <!-- Temporarily removed per Bill request 171114 PL --> <a href="/donate">Donate</a> | <a href="/about">About</a> </div> <!-- Nav --> </div> <!-- Header --> <div id="body"> <div class="homePageMessage"> <img src="/assets/images/scalaTestHeading.gif" width="700" height="200" alt="ScalaTest: Simply Productive"/> </div> <p style="align: center"> <span style="font-size: 150%">Latest Release - <a href="/release_notes/3.2.19">ScalaTest and Scalactic 3.2.19</a>!</span> </p> <pre class="scala"> <span class="reserved">import</span> collection.mutable.Stack <span class="reserved">import</span> org.scalatest._ <span class="reserved">import</span> flatspec._ <span class="reserved">import</span> matchers._ <span class="reserved">class</span> <span class="type">ExampleSpec</span> <span class="reserved">extends</span> <span class="type">AnyFlatSpec</span> <span class="reserved">with</span> <span class="type">should.Matchers</span> { <span class="quotedString">"A Stack"</span> should <span class="quotedString">"pop values in last-in-first-out order"</span> in { <span class="reserved">val</span> stack = <span class="reserved">new</span> <span class="type">Stack[Int]</span> stack.push(<span class="literal">1</span>) stack.push(<span class="literal">2</span>) stack.pop() should be (<span class="literal">2</span>) stack.pop() should be (<span class="literal">1</span>) } it should <span class="quotedString">"throw NoSuchElementException if an empty stack is popped"</span> in { <span class="reserved">val</span> emptyStack = <span class="reserved">new</span> <span class="type">Stack[Int]</span> a [<span class="type">NoSuchElementException</span>] should be thrownBy { emptyStack.pop() } } } </pre> <div style="text-align: left"> <p> ScalaTest is the most flexible and most popular testing tool in the Scala ecosystem. With ScalaTest, <strong>you can test Scala, Scala.js (JavaScript), Scala Native, Dotty (Scala 3), and Java code</strong>. 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. </p> <p> Like the Scala language on which it is built, <strong>ScalaTest is designed to grow with the demands of its users</strong>: 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. </p> <p> One way ScalaTest scales down is that despite its rich feature set, <strong>ScalaTest is easy to get into</strong>. Building on what you already know from experience with other test frameworks, you can <a href="quick_start">become productive with ScalaTest</a> very quickly. </p> <p> 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 <code>FlatSpec</code>, 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: </p> </div> <pre class="scala"> $ CLASSPATH=scalatest-app_3-3.2.19.jar:scala-xml_3-2.1.0.jar $ scala -cp $CLASSPATH org.scalatest.run ExampleSpec <span class="cyanincolor">Discovery starting. Discovery completed in 21 milliseconds. Run starting. Expected test count is: 2</span> <span class="greenincolor">ExampleSpec: A Stack - should pop values in last-in-first-out order - should throw NoSuchElementException if an empty stack is popped</span> <span class="cyanincolor">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</span> <span class="greenincolor">All tests passed.</span> </pre> <div style="text-align: left"> <p> ScalaTest does not try to impose a testing philosophy on you, but rather is designed from the philosophy that <strong>the tool should get out of your way and let you work the way you find most productive</strong>. If <code>FlatSpec</code> doesn't meet your team's needs, that's not a problem. ScalaTest has several other styles to choose from. </p> </p> In short, <strong>ScalaTest is a workbench providing many small, focused tools</strong> you can compose together to solve the problems you face today, yet grow with you as your needs change tomorrow. </p> <p> Why not give it a try? Visit the <a href="/quick_start">Quick Start</a> page. </p> </div> </div> <!-- body --> <div style="font-size: 66%; margin-top: 60px"> <p> ScalaTest is brought to you by Bill Venners and Artima.<br /> ScalaTest is free, open-source software released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0 license</a>. </p> <p> If your company loves ScalaTest, please consider <a href="/sponsor">sponsoring the project</a>. </p> <p> Copyright © 2009-2025 Artima, Inc. All Rights Reserved. </p> <p> <a href="http://www.artima.com" class="no_link_hover"> <img src="/assets/images/artima100Black.png" style="margin-top: 2px" width="100" height="38" alt="artima"/> </a> </p> </div> <!-- style="..." --> </div> <!-- Container --> </body> </html>