我有一个非常简单的项目。
build.sbt:
Z
资源文件夹下的两个配置文件:
应用程序.conf
scalaVersion := "2.13.5"
lazy val testSettings = Seq(
Test / javaOptions += "-Dconfig.resource=/test.conf"
)
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.3" % Test,"com.typesafe" % "config" % "1.4.1"
)
test.conf
some-value = "value from application.conf file"
并且只有 1 个规范测试类:
SomeTestSpec:
some-value = "value from test.conf file"
当我运行测试失败时:
class SomeTestSpec extends AnyflatSpec with Matchers {
val config: Config = ConfigFactory.load()
"some test" should "read and print from test.conf" in {
val value = config.getString("some-value")
println(s"value of some-value = $value")
value shouldBe "value from test.conf file"
}
}
为什么规范读取文件 "value from [application].conf file" was not equal to "value from [test].conf file"
ScalaTestFailureLocation: SomeTestSpec at (SomeTestSpec.scala:12)
Expected :"value from [test].conf file"
actual :"value from [application].conf file"
而不是 application.conf
? build.sbt 有问题吗?:
test.conf