如何从scalatest-scala访问主方法变量

时间:2016-11-18 17:53:24

标签: scala apache-spark

我参与scala编程几天

我在这里玩scala代码

import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf

    object SimpleApp {
      def main(args:Array[String]) {
        val logFile = "../samplelog.txt"
        val conf = new SparkConf().setAppName("Simple Application")
        val sc = new SparkContext(conf)
        val logData = sc.textFile(logFile, 2).cache()
        val numAs = logData.filter(line => line.contains("a")).count()
        val numBs = logData.filter(line => line.contains("b")).count()

        def getNumAs : Long = numAs
        def getNumBs : Long = numBs

        println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
      }
    }

我的scalatest如下

import org.scalatest._

    class simpleAppTest extends FunSuite with Matchers {

    test ("number of a's and b's")

    val acount=SimpleApp.numAs
    val bcount=SimpleApp.numBs

    acount should be(2)
    bcount should be(1)


    }

问题是我无法获得getnumAs和getnumBs的值。编译器抱怨getnumAs / getnumBs不是unit的值。我试着寻找scaladocs或示例代码,但不知道如何解决这个问题。

请帮助

感谢

0 个答案:

没有答案