Using 'scalacheck' with 'scalatest'

164 views
Skip to first unread message

Kevin Meredith

unread,
Feb 20, 2016, 9:57:56 AM2/20/16
to scalatest-users

I mistakenly thought that the `scalatest` dependency included the `scalacheck` dependency. 


But this example proved me wrong:


$cat build.sbt 

scalaVersion := "2.11.7"


libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6"

$sbt console

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0

[info] Set current project to scalatest_sandbox (in build file:/Users/kmmere/Workspace/Personal/scalatest_sandbox/)

[info] Starting scala interpreter...

[info] 

Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_51).

Type in expressions to have them evaluated.

Type :help for more information.


scala> import org.scalacheck.Gen

<console>:10: error: object scalacheck is not a member of package org

       import org.scalacheck.Gen

                  ^


I presume then that, if I want to use the scalacheck library, that I must also include it?

Kevin Meredith

unread,
Feb 20, 2016, 10:09:47 AM2/20/16
to scalatest-users
Actually, I should've read the docs - my mistake.

> Generator-driven property checks usesScalaCheck, so you must also include the ScalaCheck JAR file 
>   on your classpath when you compile and run your tests.


However, is there a recommended pairing on which scalacheck + scalatest JARs to use?

I just saw a `IncompatibleClassChangeError` thrown when trying to use the following build.sbt:

scalaVersion := "2.11.7"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6"

libraryDependencies += "org.scalacheck" % "scalacheck_2.11" % "1.13.0"

java.lang.IncompatibleClassChangeError: Implementing class

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:760)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

at java.net.URLClassLoader.access$100(URLClassLoader.java:73)

at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

at java.net.URLClassLoader$1.run(URLClassLoader.java:362)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

Bill Venners

unread,
Feb 20, 2016, 12:41:56 PM2/20/16
to scalate...@googlegroups.com
Hi Kevin,

Best place to look for the version of ScalaCheck ScalaTest was built with is to look at the pom. Here's the pom for 2.2.6:

https://oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.11/2.2.6/scalatest_2.11-2.2.6.pom

This is the relevant part:

<dependency>
  <groupId>org.scalacheck</groupId>
  <artifactId>scalacheck_2.11</artifactId>
  <version>1.12.5</version>
  <optional>true</optional
<dependency>

So if you use version 1.12.5 of ScalaCheck it should be fine. We don't have a build for 1.13.0 yet, and have been waiting on a bug fix for this:

https://github.com/rickynils/scalacheck/issues/218

Bill


--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com
Reply all
Reply to author
Forward
0 new messages