Create a custom arbitrary data generator to test Java code from ScalaTest ScalaCheck

Is it possible to create an arbitrary arbitrary generator in ScalaTest (which mixes Checkers for the ScalaCheck property) that tests Java code? eg. next necessary steps for each test inside forAll

val fund = new Fund()
val fundAccount = new Account(Account.RETIREMENT)
val consumer = new Consumer("John")
.createAccount(fundAccount)
fund.addConsumer(consumer)
fundAccount.deposit(amount)

above - a preliminary code before approving the results, etc.

+4
source share
1 answer

Are you sure you can. That should get you started.

import org.scalacheck._
import Arbitrary._
import Prop._

case class Consumer(name:String)

object ConsumerChecks extends Properties("Consumer") {
  lazy val genConsumer:Gen[Consumer] = for {
    name <- arbitrary[String]
  } yield Consumer(name)

  implicit lazy val arbConsumer:Arbitrary[Consumer] = Arbitrary(genConsumer)

  property("some prop") = forAll { c:Consumer =>
    // Check stuff
    true
  }
}
+14
source

Source: https://habr.com/ru/post/1527406/


All Articles