Reputation: 95
I am a scala noob and I am working on writing unit test cases for a scala spark program. When I try to run my scala unit test case using sbt test
command, I get the following error
BasicACRStatsTest.scala:8: not found: type BasicACRStats
[error] var basicStats: BasicACRStats = _
[error] ^
BasicACRStatsTest.scala:14: not found: type BasicACRStats
[error] basicStats = new BasicACRStats
[error] ^
[error] two errors found
[error] (test:compile) Compilation failed
I am using intellij and when I am trying to refer the class BasicACRStats
it shows Cannot resolve symbol BasicACRStats
even though I have declared it in the correct package.
BasicACRStat.scala
package com.company.analytics
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.hadoop.fs.FileSystem.Statistics
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.hive.HiveContext
import scala.collection.mutable.ArrayBuffer
import collection.mutable
object BasicACRStats {
def main(args: Array[String]) {
// Some code goes here
}
}
BasicACRStatsTest.scala
import com.company.analytics
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
class BasicACRStatsTest extends FunSuite with BeforeAndAfter {
@transient var sc: SparkContext = _
var basicStats: BasicACRStats = _
// some code goes here
}
Simple.sbt
name := "basicACRStats"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.2.0"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.1.0"
libraryDependencies += "org.apache.spark" % "spark-hive_2.10" % "1.1.0"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
Project Directory Structure
projectfoo
.idea
src
main
scala
com
company
analytics
BasicACRStats.scala
test
scala
BasicACRStatTest.scala
target
simple.sbt
I am not sure on how to troubleshoot this issue, please share your thoughts and please let me know if you would require further information.
Upvotes: 5
Views: 17826
Reputation: 11479
BasicACRStats
seems to be an object
in your sample code, not a class
.
An object is a singleton and not a class/type. I has a type, in this case BasicACRStats.type
, that there is only one instance of ever. Since it isn't a type calling new BasicACRStats
is not valid Scala and neither is trying to use it as a type for a value.
What you want is probably to declare BasicACRStats
a class. That would make the rest of your sample code make sense.
Upvotes: 3