FunSuite missing even though ScalaTest is imported
Asked Answered
L

1

12

I want to start writing simple tests in Scala using ScalaTest.
But for some reason, I can access org.scalatest but not org.scalatest.FunSuite
This is what my build.sbt looks like:

name := "Algorithms"

version := "0.1"

scalaVersion := "2.13.3"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"

I don't understand if it can access scalatest then why are FunSuite,FlatSpec and other styles missing?

Output of running test on sbt shell

[error] <Project Path>\Algorithms\src\test\scala\Course1\Week1\MaxPairProductTest.scala:3:48: type FunSuite is not a member of package org.scalatest
[error] class MaxPairProductTest extends org.scalatest.FunSuite {
[error]                                                ^
Leifeste answered 1/7, 2020 at 15:12 Comment(0)
N
33

ScalaTest 3.2.0 has completed modularisation of the monolith from prior versions

The main change in ScalaTest 3.2.0 is carrying out the modularization that we prepared for in 3.0.8 and 3.1.0. As a result, many deprecated names have been removed, because the deprecations would cross module boundaries.

This means that whilst in 3.1.0 the following definition

import org.scalatest.FunSuite
 
class ExampleSuite310 extends FunSuite {}

would just raise deprecation notice

The org.scalatest.FunSuite trait has been moved and renamed. Please use org.scalatest.funsuite.AnyFunSuite instead. This can be rewritten automatically with autofix: https://github.com/scalatest/autofix/tree/master/3.1.x", "3.1.0"

in 3.2.0 it has been removed entirely. Hence from 3.2.0 onwards you should define like so

import org.scalatest.funsuite.AnyFunSuite

class ExampleSuite320 extends AnyFunSuite {}

See deprecations expirations for full list of new names.

Note we can still import a single artifact which will pull transitively all the sub-artifacts

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"

however now we also have the options of depenending on just the particular sub-artifact

libraryDependencies += "org.scalatest" %% "scalatest-funsuite" % "3.2.0" % "test"
Nimocks answered 1/7, 2020 at 15:28 Comment(3)
Thank You so much. This fixed it. However, why was I not getting that Depracation notice? Not even the website's instruction mentioned this.Leifeste
@VarunGawande Deprecation warnings seem to work for me in 3.1.0. Try with ;clean;set Test/scalacOptions += "-deprecation";Test/compile;. Indeed website seems to be out-of-date in few places, however scaladoc seems to be well maintained. Personally, I keep an eye on github.com/scalatest/scalatest/releases which should have the most up-to-date information.Nimocks
Probably this tutorial from the official documentation for Scala needs an update - docs.scala-lang.org/getting-started/intellij-track/… :-|Annmaria

© 2022 - 2024 — McMap. All rights reserved.