Raiyan Kabir
Raiyan Kabir

Reputation: 1016

SBT cannot resolve class declared in src/main/scala in a src/test/scala test class

I am trying to make my own custom CSV reader. I am using IntelliJ IDEA 14 with sbt and specs2 test framework.

The class I declared in src/main is as follows:

import java.io.FileInputStream

import scala.io.Source

class CSVStream(filePath:String) {
  val csvStream = Source.fromInputStream(new FileInputStream(filePath)).getLines()
  val headers = csvStream.next().split("\\,", -1)
}

The content of the test file in src/test is as follows:

import org.specs2.mutable._

object CSVStreamSpec {

  val csvSourcePath = getClass.getResource("/csv_source.csv").getPath
}

class CSVStreamSpec extends Specification {
  import CSVStreamLib.CSVStreamSpec._

  "The CSV Stream reader" should {
    "Extract the header" in {
      val csvSource = CSVStream(csvSourcePath)
    }
  }
}

The build.sbt file contains the following:

name := "csvStreamLib"

version := "1.0"

scalaVersion := "2.11.4"

libraryDependencies ++= Seq("org.specs2" %% "specs2-core" % "2.4.15" % "test")

parallelExecution in Test := false

The error I am getting when I type test is as follows:

[error] /Users/raiyan/IdeaProjects/csvStreamLib/src/test/scala/csvStreamSpec.scala:18: not found: value CSVStream
[error]       val csvSource = CSVStream(csvSourcePath)
[error]                       ^
[error] one error found
[error] (test:compile) Compilation failed
[error] Total time: 23 s, completed 30-Dec-2014 07:44:46

How do I make the CSVStream class accessible to the CSVStreamSpec class in the test file?

Update:

I tried it with sbt in the command line. The result is the same.

Upvotes: 0

Views: 688

Answers (1)

sjrd
sjrd

Reputation: 22085

You forgot the new keyword. Without it, the compiler looks for the companion object named CSVStream, not the class. Since there is none, it complains. Add new and it'll work.

Upvotes: 2

Related Questions