scalacheck | Property-based testing for Scala | Build Tool library
kandi X-RAY | scalacheck Summary
kandi X-RAY | scalacheck Summary
ScalaCheck is a library written in Scala and used for automated property-based testing of Scala or Java programs. ScalaCheck was originally inspired by the Haskell library QuickCheck, but has also ventured into its own. ScalaCheck has no external dependencies other than the Scala runtime, and works great with SBT, the Scala build tool. It is also fully integrated in the test frameworks ScalaTest and specs2. You can of course also use ScalaCheck completely standalone, with its built-in test runner. ScalaCheck is used by several prominent Scala projects, for example the Scala compiler and the Akka concurrency framework.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scalacheck
scalacheck Key Features
scalacheck Examples and Code Snippets
Community Discussions
Trending Discussions on scalacheck
QUESTION
I stumbled upon this challenge on stackoverflow while learning about property based testing in scala using ScalaCheck.
Find the smallest positive integer that does not occur in a given sequence
I thought of trying to write a generator driven property based test for this problem to check the validity of my program but can't seem to be able to think of a how to write a relevant test case. I understand that I could write a table driven property based testing for this use case but that limit the number of properties I could test this algo with.
...ANSWER
Answered 2021-Jun-24 at 22:33Using Scalatest's (since you did tag scalatest
) Scalacheck integration and Scalatest matchers, something like
QUESTION
I've scala and scalajs project and it is in github for reference.
Initially I've scalatest version 3.0.3 and scalacheck version 1.13.5. The command sbt clean test
is working fine.
I've updated scalatest version to 3.1.4 and scalacheck version 1.14.3.
After this updated scala project tests are working fine but scalajs tests are not.
The error I'm getting is
[info] Fast optimizing /Users/rajkumar.natarajan/Documents/Coding/misc/sjs-test-error/core/js/target/scala-2.12/reftree-test-fastopt.js
[error] Referring to non-existent method org.scalatestplus.scalacheck.ScalaCheckConfiguration.$$init$()scala.Unit
[error] called from generic.RefTreeSpec.()
[error] called from generic.RefTreeSpec.()
[error] called from core module analyzer
[error] Referring to non-existent method org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks.$$init$()scala.Unit
[error] called from generic.RefTreeSpec.()
[error] called from generic.RefTreeSpec.()
[error] called from core module analyzer
[error] There were linking errors
[error] (coreJS / Test / fastOptJS) There were linking errors
[error] Total time: 31 s, completed Jun 9, 2021, 5:54:57 PM
The changes are in this commit.
I tried to figure out but I'm novice in scalajs. Is there anything extra I need to do to work correctly?
...ANSWER
Answered 2021-Jun-09 at 22:19QUESTION
I am curious to know if it is possible to fully test following code with Pitest/ScalaCheck
Methods to test:
...ANSWER
Answered 2021-May-14 at 13:28The call to scala/MatchError
is synthesized by the compiler for the case where the match fails (it's the call to MatchError
's constructor which gets thrown if none of the case
s in the pattern match apply). Since your pattern match is in fact exhaustive, there's no way for the match to fail, ergo there's no way in Scala to force the match to fail (this is assuming that you're using the standard library List
; if you're using your own implementation of List
, perhaps it's not sealed
?)
It's perhaps a Scala compiler bug that it generates bytecode for failed pattern matches which can't fail.
I'm not familiar with pitest, but it's likely that it doesn't understand Scala (or the higher level semantic meaning of the bytecode emitted by the Scala compiler); tools which rely on bytecode manipulation are likely to not always work as they would for Java with Scala.
QUESTION
I am learning FP and got introduced to the concept of property-based testing and for someone from OOP world PBT looks both useful and dangerous. It does check a lot of options, but what if there is one (or some) options that fail, but they didn't fail during your first let's say Jenkins build. Then next time you run the build the test may or may not fail, doesn't it kill the entire idea of repeatable builds?
I see that some people explored options to make the tests deterministic, but then if such test doesn't catch an error it will never catch it.
So what's better approach here? Do we sacrifice build repeatability to eventually uncover a bug or do we take the risk of never uncovering it, but get our repeatability back?
(I hope that I properly understood the concept of PBT, but if I didn't I would appreciate if somebody could point out my misconceptions)
...ANSWER
Answered 2021-May-14 at 13:24Doing a lot of property-based testing I don’t see indeterminism as a big problem. I basically experience three types of it:
A property is really indeterministic b/c some external factor - e.g. timeout, delay, db config - makes it so. Those flaky tests also show up in example-based testing and should be eliminated by making the external factor deterministic.
A property fails rarely because the triggering condition is only sometimes met by pseudo random data generation. Most PBT libraries have ways to reproduce those failing runs, eg by re-using the random seed of the failing test run or even remembering the exact constellation in a database of some sort. Those failures reveal problems and are one of the reasons why we’re doing random test cases generation in the first place.
Coverage assertions („this condition will be hit in at least 5 percent of all cases“) may fail from time to time even though they are generally true. This can be mitigated by raising the number of tries. Some libs, eg quickcheck, do their own calculation of how many tries are needed to prove/disprove coverage assumptions and thereby mostly eliminate those false positives.
The important thing is to always follow up on flaky failures and find the bug, the indeterministic external factor or the wrong assumption in the property‘s invariant. When you do that, sporadic failures will occur less and less often. My personal experience is mostly with jqwik but other people have been telling me similar stories.
QUESTION
in munit scalacheck, how do I limit the number of inputs required to pass the test?
...ANSWER
Answered 2021-Apr-06 at 09:17If your test extends munit.ScalaCheckSuite
, there is a protected def scalaCheckTestParameters
you can override to set the test parameters. A good way to set it is to modify the value in the base class, for example
QUESTION
I am fairly new to ScalaCheck and somehow I want to generate a list of distinct values (i.e. a set). With my approach the values are not unique.
...ANSWER
Answered 2021-Apr-21 at 01:42Crude but effective:
QUESTION
Is it possible to lift custom generating function into Gen
?
For example, generating ObjectId
s for mongo.
ANSWER
Answered 2021-Mar-23 at 14:30Gen.delay(Gen.const(new ObjectId))
QUESTION
I have a scalacheck test with case class Payment
Seq and I want to check and generate Seq
with 10,000 elements. Could you tell me please how to control the amount of elements in Seq
in test?
ANSWER
Answered 2021-Mar-07 at 15:42You can use containerOfN
:
QUESTION
I upgraded my test dependencies for my play project and now I get this problem:
...ANSWER
Answered 2021-Jan-13 at 08:00You don't have the right dependency:
QUESTION
Using a basic example I'm attempting to randomly generate a bunch of Person (case class Person(name: String, age: Int
) instances using this library for random data generation.
The problem I'm running into is when creating an Arbitrary that has bound limits for the age parameter as shown below.
...ANSWER
Answered 2020-Nov-13 at 19:38Even though an implicit value is seldom, if ever, referenced by name, it still needs one, what the language spec calls a "stable identifier."
Using _
as the variable name tells the compiler that it can forget about this value after it's been created.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scalacheck
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page