Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用junit';s BeforeClass注释在scala中的顶级对象中的行为?_Scala_Apache Spark_Junit_Annotations_Singleton - Fatal编程技术网

如何使用junit';s BeforeClass注释在scala中的顶级对象中的行为?

如何使用junit';s BeforeClass注释在scala中的顶级对象中的行为?,scala,apache-spark,junit,annotations,singleton,Scala,Apache Spark,Junit,Annotations,Singleton,我有一个初学者的问题: 我有一个基于spark的scala项目,它使用junit。 这是项目的重要部分: object ResearchCrawlServiceTestSuite { implicit var ss: SparkSession = _ var fs: FileSystem = _ @BeforeClass def init(): Unit = { ss = SparkSession.builder().master("local").getOrCrea

我有一个初学者的问题: 我有一个基于spark的scala项目,它使用junit。 这是项目的重要部分:

object ResearchCrawlServiceTestSuite {
  implicit var ss: SparkSession = _
  var fs: FileSystem = _


  @BeforeClass
  def init(): Unit = {
    ss = SparkSession.builder().master("local").getOrCreate()
    fs = get(ss.sparkContext.hadoopConfiguration)
  }
}

class ResearchCrawlServiceTestSuite {
  self =>
  private object testImplicits extends SQLImplicits {
    protected override def _sqlContext: SQLContext = self.ss.sqlContext
  }

  import testImplicits._

  implicit val ss: SparkSession = ResearchCrawlServiceTestSuite.ss
  val fs: FileSystem = ResearchCrawlServiceTestSuite.fs

  @Test def submitCrawlSanity() {
    val seeds = (0 to 4).map(i => s"www.$i.com").toDF("url")
    ...
   }
}
如果我将对象的名称更改为与它下面的类不同,那么@BeforeClass方法似乎不会运行。 我的问题是,@BeforeClass注释什么时候运行? 它在不是伴生对象的顶级对象中的行为如何? 它在作为伴星的顶级对象中的行为如何? 它在嵌套对象中的行为如何