I'm using the frameworks mentioned in the title with the following configuration:
"com.typesafe.play" % "sbt-plugin" % "2.4.2"
"org.scalacheck" %% "scalacheck" % "1.12.4" % "test"
"org.scalatest" %% "scalatest" % "2.2.5" % "test"
"org.scalatestplus" %% "play" % "1.4.0-M4" % "test"
With a simple test for the purpose of demonstration:
class User
extends FlatSpec
with Matchers
with Checkers {
it should "do scala check stuff" in {
check( ( a: Int ) ⇒ a > 100 )
}
it should "do scala check stuff II" in {
check( ( a: Int ) ⇒ true )
}
}
It appears to basically work, but the sbt test
output is cluttered with exceptions.
[project-id] $ test
[info] User:
[info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[info] p.a.l.c.ActorSystemProvider - Shutdown application default Akka system: application
[info] - should do scala check stuff *** FAILED ***
[info] GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info] (User.scala:157)
[info] Falsified after 0 successful property evaluations.
[info] Location: (User.scala:157)
[info] Occurred when passed generated values (
[info] arg0 = -1
[info] )
Exception in thread "Thread-31" java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.List$SerializationProxy to field org.scalacheck.Test$Failed.args of type scala.collection.immutable.List in instance of org.scalacheck.Test$Failed
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2089)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1261)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1999)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.scalatest.tools.Framework$ScalaTestRunner$Skeleton$1$React.react(Framework.scala:953)
at org.scalatest.tools.Framework$ScalaTestRunner$Skeleton$1.run(Framework.scala:942)
at java.lang.Thread.run(Thread.java:745)
Reporter completed abruptly with an exception after receiving event: TestFailed(Ordinal(0, 3),GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
(User.scala:157)
Falsified after 0 successful property evaluations.
Location: (User.scala:157)
Occurred when passed generated values (
arg0 = -1
),User,test.api.controller.User,Some(test.api.controller.User),should do scala check stuff,should do scala check stuff,Vector(),Some(org.scalatest.exceptions.GeneratorDrivenPropertyCheckFailedException: GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
(User.scala:157)
Falsified after 0 successful property evaluations.
Location: (User.scala:157)
Occurred when passed generated values (
arg0 = -1
)),Some(3210),Some(IndentedText(- should do scala check stuff,should do scala check stuff,0)),Some(SeeStackDepthException),Some(test.api.controller.User),None,pool-1-thread-1-ScalaTest-running-User,1440662150684).
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1286)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1231)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1427)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1577)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at org.scalatest.tools.SocketReporter.apply(SocketReporter.scala:31)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:240)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:239)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:239)
at java.lang.Thread.run(Thread.java:745)
Reporter completed abruptly with an exception after receiving event: TestStarting(Ordinal(0, 4),User,test.api.controller.User,Some(test.api.controller.User),should do scala check stuff II,should do scala check stuff II,Some(MotionToSuppress),Some(LineInFile(160,User.scala)),Some(test.api.controller.User),None,pool-1-thread-1-ScalaTest-running-User,1440662150704).
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1286)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1231)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1427)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1577)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at org.scalatest.tools.SocketReporter.apply(SocketReporter.scala:31)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:240)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:239)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:239)
at java.lang.Thread.run(Thread.java:745)
[info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[info] p.a.l.c.ActorSystemProvider - Shutdown application default Akka system: application
[info] - should do scala check stuff II
Reporter completed abruptly with an exception after receiving event: TestSucceeded(Ordinal(0, 5),User,test.api.controller.User,Some(test.api.controller.User),should do scala check stuff II,should do scala check stuff II,Vector(),Some(506),Some(IndentedText(- should do scala check stuff II,should do scala check stuff II,0)),Some(LineInFile(160,User.scala)),Some(test.api.controller.User),None,pool-1-thread-1-ScalaTest-running-User,1440662151215).
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1286)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1231)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1427)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1577)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at org.scalatest.tools.SocketReporter.apply(SocketReporter.scala:31)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:240)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:239)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:239)
at java.lang.Thread.run(Thread.java:745)
Reporter completed abruptly with an exception after receiving event: SuiteCompleted(Ordinal(0, 6),User,test.api.controller.User,Some(test.api.controller.User),Some(3850),Some(MotionToSuppress),Some(TopOfClass(test.api.controller.User)),None,None,pool-1-thread-1,1440662151227).
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.writeByte(ObjectOutputStream.java:1915)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1576)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at org.scalatest.tools.SocketReporter.apply(SocketReporter.scala:31)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:240)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:239)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:239)
at java.lang.Thread.run(Thread.java:745)
Reporter completed abruptly with an exception after receiving event: RunCompleted(Ordinal(0, 7),Some(4099),Some(Summary(1,1,0,0,0,1,0,0)),None,None,None,main,1440662151252).
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.writeByte(ObjectOutputStream.java:1915)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1576)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at org.scalatest.tools.SocketReporter.apply(SocketReporter.scala:31)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:240)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$1.apply(DispatchReporter.scala:239)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:239)
at java.lang.Thread.run(Thread.java:745)
Reporter completed abruptly with an exception on invocation of the dispose method.
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1822)
at java.io.ObjectOutputStream.flush(ObjectOutputStream.java:719)
at org.scalatest.tools.SocketReporter.dispose(SocketReporter.scala:37)
at org.scalatest.DispatchReporter$.propagateDispose(DispatchReporter.scala:312)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$2.apply(DispatchReporter.scala:251)
at org.scalatest.DispatchReporter$Propagator$$anonfun$run$2.apply(DispatchReporter.scala:250)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.DispatchReporter$Propagator.run(DispatchReporter.scala:250)
at java.lang.Thread.run(Thread.java:745)
[info] ScalaCheck
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] ScalaTest
[info] Run completed in 4 seconds, 976 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Failed: Total 2, Failed 1, Errors 0, Passed 1
[error] Failed tests:
[error] test.api.controller.User
[error] (api/test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 6 s, completed 27.08.2015 09:55:51
I am also confused by the fact that there are 3 test summaries at the end of the log, whereof 2 contain no useful information.
Your test and code seems ok.
You probably already know that, but anyway, your first test is just failing (don't mind the weird exceptions yet).
Fixing the first test, replacing it with:
check( ( a: Int ) ⇒ a / 1 == a )
We get:
[info] User:
[info] - should do scala check stuff (1 second, 421 milliseconds)
[info] - should do scala check stuff II (28 milliseconds)
[info] ScalaCheck
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] ScalaTest
[info] Run completed in 12 seconds, 132 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 23 s, completed Feb 14, 2016 12:44:44 AM
What about those 3 test summaries?
ScalaCheck and ScalaTest are two separate test frameworks, although you are using some of the functionality of ScalaCheck inside ScalaTest. But sbt doesn't know about that and since you included both frameworks, it looks for the two kind of tests, and report the results for each framework.
That's why ScalaCheck's report is printed with 0 runned tests. After this, ScalaTest's tests are runned and you get the report. The third and last report is from sbt itself, summarizing the results from all test frameworks.
Back to the weird exceptions, they will only appear if your testing are failing, so you shouldn't worry too much about them. But if it is really annoying you, add this to your build.sbt
:
fork in Test := false
And the weird exceptions will go away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With