mbee mbee - 24 days ago 7x
Scala Question

ScalaTest: referencing NoArgTest

I am playing around with sharing fixtures, especially withFixture(NoArgTest). However, my code does not compile if referencing NoArgTest.

My only dependency:


My code trying to reference NoArgTest as a type:

1 class Example {
2 def foo(test: org.scalatest.TestSuite) = "foo"
3 def bar(test: org.scalatest.TestSuite.NoArgTest) = "bar"
4 }

mvn compile:

[WARNING] Expected all dependencies to require Scala version: 2.11.8
[WARNING] org.scalatest:scalatest_2.11:3.0.0 requires scala version: 2.11.8
[WARNING] org.scalactic:scalactic_2.11:3.0.0 requires scala version: 2.11.8
[WARNING] org.scala-lang:scala-reflect:2.11.8 requires scala version: 2.11.8
[WARNING] org.scala-lang.modules:scala-xml_2.11:1.0.5 requires scala version: 2.11.7
[WARNING] Multiple versions of scala libraries detected!


[ERROR] Example.scala:4: error: object TestSuite is not a member of package org.scalatest
[ERROR] Note: trait TestSuite exists, but it has no companion object.
[ERROR] def bar(test: org.scalatest.TestSuite.NoArgTest) = "bar"



You can write TestSuite#NoArgTest (this is the common type of all NoArgTests independent of the suite), or suite.NoArgTest if you already have an instance suite: TestSuite. Note that if suite is a member parameter, they need to be in separate parameter lists:

def bar(suite: TestSuite)(test: suite.NoArgTest) = ...

See the answers to What are the differences between Scala’s inner classes and Java’s Inner/nested classes? for more details.