找不到 GeneratorDrivenPropertyChecks 特性

Moj*_*ojo 8 scala scalatest

我定义了这些测试依赖项

/ Test Dependencies
lazy val wiremock             = "com.github.tomakehurst"      % "wiremock-jre8"             % "2.25.1"
lazy val playTest             = "com.typesafe.play"          %% "play-test"                 % "2.8.1"
lazy val scalaTestPlusPlay    = "org.scalatestplus.play"     %% "scalatestplus-play"        % "5.1.0"
lazy val mockito              = "org.mockito"                %% "mockito-scala"             % "1.10.2"
lazy val scalamock            = "org.scalamock"              %% "scalamock"                 % "4.4.0"
lazy val scalacheck_shapeless = "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.3"
lazy val scalatest            = "org.scalatest"              %% "scalatest"                 % "3.1.1"
Run Code Online (Sandbox Code Playgroud)

但是我找不到这个特性来混合到我的测试规范类中:GeneratorDrivenPropertyChecks。我不确定我在这里缺少什么依赖项。在org.scalatest.prop我没有看到这个特征。我只看到 TableDrivenPropertyChecks。

Mar*_*lic 14

GeneratorDrivenPropertyChecks似乎已在 ScalaTest 3.1.0 中删除

我们将其设为私有,以便它不再阻碍 3.1.0 版本的发布。我想研究一种更好的方法来集成收缩,就像 Hedgehog 等工具所做的那样。除了模块化之外,我们希望 3.2.0 版本与 3.1.0 完全相同。之后我们计划完成并发布 ScalaTest 的 Generator。同时,我们认为每个人都会继续使用 ScalaCheckDrivenPropertyChecks 和 Gen,它可以在这里找到:

https://github.com/scalatest/scalatestplus-scalacheck

而是尝试ScalaCheckDrivenPropertyChecks像这样使用

import org.scalacheck.Gen
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

class HelloSpec extends AnyFlatSpec with Matchers with ScalaCheckDrivenPropertyChecks {
  "ScalaCheckDrivenPropertyChecks" should "provide forAll" in {
    forAll(Gen.choose(1, 100)) { i =>
      i shouldBe i
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在哪里

libraryDependencies ++= Seq(
  "org.scalatestplus" %% "scalacheck-1-14" % "3.1.1.1" % Test,
  "org.scalatest" %% "scalatest" % "3.1.1" % Test
)
Run Code Online (Sandbox Code Playgroud)

  • 我们使用的是 3.2.0 版本,[文档](https://www.scalatest.org/user_guide/property_based_testing) 仍然引用旧的不存在的特征。在尝试在各种博客及其 GitHub 中找到答案后,我花了 25 分钟才找到这个答案:/ Hvala Mario! (6认同)