Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FunSuite missing even though ScalaTest is imported

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]                                                ^
like image 760
Varun Gawande Avatar asked Jul 01 '20 15:07

Varun Gawande


1 Answers

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"
like image 143
Mario Galic Avatar answered Nov 13 '22 06:11

Mario Galic