我正在尝试将标度计测试添加到我现有的项目中。根据文档,我可以 add 这段代码 到我的 build.sbt 然后我应该能够调用
sbt bench:test
并且只运行基准测试。但是,当我运行命令时,出现此错误:
$ sbt "bench:test"
[info] welcome to sbt 1.8.2 (N/A Java 17.0.6)
<snip>
[error] No such setting/task
[error] bench:test
[error]
当我在 sbt shell 中列出任务时,我看不到 bench 任务的迹象。我怎样才能让它工作?
我已经在
src/bench/scala/EndpointBenchmark.scala
中创建了基准文件以防万一。我不完全确定测试应该放在哪里。
我查看了 sbt 文档并搜索了上面的错误,但我找不到任何提及如何处理根本找不到设置/任务的情况。我假设我需要以某种方式将它添加到根项目中?
build.sbt
val scalaVersionString = "2.13.10"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := scalaVersionString
val AkkaVersion = "2.7.0"
val AkkaHttpVersion = "10.5.0"
lazy val root = (project in file("."))
.settings(
name := "sample_project"
)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.maximeroussy.invitrode" % "invitrode" % "2.0.2",
"org.scalatest" %% "scalatest" % "3.2.15" % Test,
"com.storm-enroute" %% "scalameter" % "0.21" % Test,
"ch.qos.logback" % "logback-classic" % "1.4.5"
)
lazy val Benchmark = config("bench") extend Test
/** This allows running ScalaMeter benchmarks in separate sbt configuration.
* It means, that when you want run your benchmarks you should type `bench:test` in sbt console.
*/
lazy val basic = (project in file("."))
.settings(Defaults.coreDefaultSettings ++ Seq(
name := "sample_project_benchmarks",
scalaVersion := scalaVersionString,
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xlint"),
publishArtifact := false,
libraryDependencies ++= Seq(
"com.storm-enroute" %% "scalameter" % "0.21" % "bench"
),
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
),
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
Benchmark / parallelExecution := false,
logBuffered := false
)
) configs(
Benchmark
) settings(
inConfig(Benchmark)(Defaults.testSettings): _*
)