Scalatest访问Fixture属性

时间:2017-05-25 01:15:09

标签: scala scalatest

如何在TestSuiteParams内访问我的before

我正在使用Runner

运行我的测试
import org.scalatest.tools.Runner
val runnerArray: Array[String] = Array("-s", "com.inn.org.functional.Stateless", "-Dmonth=1")    
Runner.run(runnerArray)

我在month中有TestSuiteParams属性我希望在before中访问,但我不确定如何访问它。

到目前为止,我的测试格式如何

class Stateless extends fixture.FeatureSpec with BeforeAndAfter {

    before("before") {
        // I want to access TestSuiteParams HERE
        // but I cannot!
    }

    feature("feature") {
        scenario() {TestSuiteParams =>
            // this piece works! I can access .month!
            assert(TestSuiteParams.month != null)
        }
    }

    def withFixture(test: OneArgTest): org.scalatest.Outcome = {
        val hiveContext = new HiveContext(sc)
        test(TestSuiteParams(hiveContext, 1)
    }

    case class TestSuiteParams(hiveContext: HiveContext, month: String)
}

1 个答案:

答案 0 :(得分:1)

您必须将配置图注入您的测试类,如下所示。

import org.scalatest.{ConfigMapWrapperSuite, WrapWith}

@WrapWith(classOf[ConfigMapWrapperSuite])
class Stateless(configMap: Map[String, Any]) extends fixture.FeatureSpec with BeforeAndAfter {
   before("before") {
       configMap("month")
    }
}