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"> <a href="/">Home</a> | <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> | <span><em>SuperSafe</em></span> | <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="message"> <a class="scalatestLogo" href="./"> <img src="/assets/images/scalaTestLogo.gif" width="400" height="60" alt="ScalaTest"/> </a> </div> <div style="text-align: left"> <h1>ScalaTest support in SuperSafe Community Edition</h1> <p> <a href="http://www.artima.com/supersafe_user_guide.html">Artima SuperSafe</a> is a commercial Scala compiler plugin with a free Community Edition that checks ScalaTest/Scalactic <code>===</code> and matcher expressions for correctness. Using SuperSafe Community Edition together with ScalaTest can save you time and ensure certain errors do not exist in your code. (See the <a href="#installation">installation section</a> below for instructions on installing SuperSafe Community Edition.) </p> <pre class="scala"> scala> <span class="reserved">import</span> org.scalatest._ <span class="lineComment">import org.scalatest._</span> scala> <span class="reserved">import</span> Assertions._ <span class="lineComment">import Assertions._</span> scala> val x = <span class="type">Some</span>(<span class="literal">1</span>) <span class="lineComment">x: Some[Int] = Some(1)</span> scala> assert(x === <span class="literal">1</span>) <span class="lineComment"><console>:18: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared with the === operator. If you really want to compare them for equality, configure Artima SuperSafe to allow those types to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality assert(x === 1) ^</span> scala> assert(x !== <span class="literal">1</span>) // Note this assertion would have succeeded <span class="lineComment"><console>:18: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared with the !== operator. If you really want to compare them for inequality, configure Artima SuperSafe to allow those types to be compared for inequality (which will also enable them to be compared for equality). For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality assert(x !== 1) ^</span> scala> <span class="reserved">import</span> Matchers._ <span class="lineComment">import Matchers._</span> scala> x should equal (<span class="literal">1</span>) <span class="lineComment"><console>:21: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared for equality with ScalaTest's equal matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and Int to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should equal (<span class="literal">1</span>) ^</span> scala> x should not equal 1 // Note this assertion would have succeeded <span class="lineComment"><console>:21: error: [Artima SuperSafe] Values of type Some[Int] and Int may not be compared for equality with ScalaTest's not equal matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and Int to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should not equal 1 ^</span> scala> x shouldBe <span class="quotedString">"hi"</span> <span class="lineComment"><console>:21: error: [Artima SuperSafe] Values of type Some[Int] and String may not be compared for equality with ScalaTest's shouldBe matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x shouldBe "hi" ^</span> scala> x should === (<span class="quotedString">"hi"</span>) <span class="lineComment"><console>:21: error: [Artima SuperSafe] Values of type Some[Int] and String may not be compared for equality with ScalaTest's === matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Some[Int] and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality x should === ("hi") ^</span> scala> List(<span class="literal">1</span>, <span class="literal">2</span>, <span class="literal">3</span>) should contain (<span class="quotedString">"hi"</span>) <span class="lineComment"><console>:20: error: [Artima SuperSafe] Values of type Int and String may not be compared for equality with ScalaTest's contain matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should contain ("hi") ^</span> scala> List(<span class="literal">1</span>, <span class="literal">2</span>, <span class="literal">3</span>) should not contain (<span class="quotedString">"ho"</span>) <span class="lineComment"><console>:20: error: [Artima SuperSafe] Values of type Int and String may not be compared for equality with ScalaTest's contain matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and String to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should not contain ("ho") ^</span> scala> List(<span class="literal">1</span>, <span class="literal">2</span>, <span class="literal">3</span>) should contain oneOf (<span class="quotedString">"hi"</span>, <span class="quotedString">"ho"</span>) <span class="lineComment"><console>:20: error: [Artima SuperSafe] Values of type List[Int] and String may not be compared for equality with ScalaTest's oneOf matcher syntax. If you really want this expression to compile, configure Artima SuperSafe to allow Int and wtring to be compared for equality. For more information on this kind of error, see: http://www.artima.com/supersafe_user_guide.html#safer-equality List(1, 2, 3) should contain oneOf ("hi", "ho") ^</span> </pre> <a name="installation"></a> <h2>Installation of SuperSafe Community Edition</h2> <p> If you are using sbt as your build tool, you can install the SuperSafe Community Edition in two easy steps. </p> <p> 1. Add the <em>Artima Maven Repository</em> as a resolver in ~/.sbt/0.13/global.sbt, like this: </p> <pre class="stGrayback"> resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases" </pre> <p> 2. Add the following line to your project/plugins.sbt: </p> <pre class="stGrayback"> addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.12") </pre> <p> <em>Note: If using ScalaTest 2.2.6 or earlier, use SuperSafe version 1.1.0-RC6 instead, which will be the last version of SuperSafe to support ScalaTest 2.x.</em> <p> <p> If you are using Maven as your build tool, you can install the community edition of SuperSafe by adding the compiler plugin to your <code>pom.xml</code>, like this: </p> <pre class="stGrayback"> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <configuration> <compilerPlugins> <b><compilerPlugin> <groupId>com.artima.supersafe</groupId> <artifactId>supersafe_2.13.14</artifactId> <version>1.1.12</version> </compilerPlugin></b> </compilerPlugins> </configuration> <executions> ... </executions> </plugin> </pre> <p> <em>Note: If using ScalaTest 2.2.6 or earlier, use SuperSafe version 1.1.0-RC6 instead, which will be the last version of SuperSafe to support ScalaTest 2.x.</em> </p> <p> Note: You need to use the exact Scala version in the artifactId, because compiler plugin depends on compiler API that's not binary compatible between Scala minor releases. </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>