如何在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)
}
答案 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")
}
}