scalatest

how to dermine if a test failed in afterEach of a FunSpec in scalatest

青春壹個敷衍的年華 提交于 2019-12-01 12:38:50
In scalatest using FunSpec I have some code that fires in the afterEach. I would like to execute some code to get a screenshot only when the test fails. Just about everything I have looked at tries to solve this by putting asserts in try blocks which seems awful. Is there anything like onTestFailure in TestNG or a context I can get like RSpec to determine if the test failed? Looking at the scala doc I see a implementation that takes a configMap, but that is empty when I run the test. Any help would be appreciated. adambsg pretty sure I figured it out. coming from a TestNG background it seemed

Failing a scalatest when akka actor throws exception outside of the test thread

混江龙づ霸主 提交于 2019-12-01 05:57:56
I've had a situation come up and bite me a few times where I'm testing an Actor and the Actor throws an exception unexpectedly (due to a bug), but the test still passes. Now most of the time the exception in the Actor means that whatever the test is verifying won't come out properly so it the test fails, but in rare cases that's not true. The exception occurs in a different thread than the test runner so the test runner knows nothing about it. One example is when I'm using a mock to verify some dependency gets called, and due to a mistake in the Actor code I call an unexpected method in the

Why does sbt say “bad symbolic reference…” for test with ScalaTest?

对着背影说爱祢 提交于 2019-12-01 04:16:34
I started using ScalaTest with sbt. The build.sbt is as follows: name := "MySpecSample" version := "1.0" libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test" scalaVersion := "2.10.3" Initial test code is here. This test code runs alone without main component code. import collection.mutable.Stack import org.scalatest._ class ExampleSpec extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) stack.pop() should be (2) stack.pop() should be (1) } it should "throw

Why “could not find implicit” error in Scala + Intellij + ScalaTest + Scalactic but not from sbt

我与影子孤独终老i 提交于 2019-12-01 02:44:57
I have this code that is working 100% from sbt , executing sbt test but throw a compilation error in Intellij Idea. import org.scalatest.{BeforeAndAfter, FunSuite, GivenWhenThen} class SimpleTest extends FunSuite with GivenWhenThen with BeforeAndAfter { test("Simple Test") { Given("Why this error?") assert("ok" === "ok") } } The error is: Error:(5, 10) could not find implicit value for parameter pos: org.scalactic.source.Position Given("Why this error?") Error:(5, 10) not enough arguments for method Given: (implicit pos: org.scalactic.source.Position)Unit. Unspecified value parameter pos.

Why does sbt say “bad symbolic reference…” for test with ScalaTest?

╄→гoц情女王★ 提交于 2019-12-01 02:02:22
问题 I started using ScalaTest with sbt. The build.sbt is as follows: name := "MySpecSample" version := "1.0" libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test" scalaVersion := "2.10.3" Initial test code is here. This test code runs alone without main component code. import collection.mutable.Stack import org.scalatest._ class ExampleSpec extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1)

Scala and Mockito with traits

半世苍凉 提交于 2019-11-30 20:44:46
I had a simple class that naturally divided into two parts, so I refactored as class Refactored extends PartOne with PartTwo Then the unit tests started failing. Below is an attempt to recreate the problem. The functionality of all three examples is the same, but the third test fails with a NullPointerException as indicated. What it is about the use of traits that is causing the problem with mockito? Edit: Is Mockito the best choice for Scala? Am I using the wrong tools? import org.scalatest.junit.JUnitSuite import org.scalatest.mock.MockitoSugar import org.mockito.Mockito.when import org

ScalaMock. Mock a class that takes arguments

女生的网名这么多〃 提交于 2019-11-30 20:31:18
Full disclosure: I'm very new to mocking and mocking frameworks. I'm trying to use ScalaMock because it seemed like the 'default' mocking framework to use with ScalaTest but I am happy to use any other framework which is compatible with ScalaTest. The problem: I've written in Scala a class that talks to a socket. The class has a type parameter of what sort of socket it is to talk to and one of it's arguments is a factory for creating sockets of that type. It has the signature: class XScanner[T <: SocketClient]( confPath: String = "/etc/default/configPath", socketClientFactory: String => T )

Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?

三世轮回 提交于 2019-11-30 17:44:00
I am getting the following error when I try to run tests in IntelliJ (2019.1), Scala IntelliJ plugin v2019.1.8, with Scala 2.13: Exception in thread "ScalaTest-dispatcher" java.lang.NoSuchMethodError: scala.collection.JavaConverters.seqAsJavaListConverter(Lscala/collection/Seq;)Lscala/collection/convert/Decorators$AsJava; at org.jetbrains.plugins.scala.testingSupport.scalaTest.treeBuilder.ParallelTreeBuilder.getOrdinalList(ParallelTreeBuilder.java:21) at org.jetbrains.plugins.scala.testingSupport.scalaTest.treeBuilder.ParallelTreeBuilder$SuiteTree.<init>(ParallelTreeBuilder.java:92) at org

SBT Test Error: java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream

不打扰是莪最后的温柔 提交于 2019-11-30 13:14:30
问题 Getting Below exception , when i tried to perform unit tests for my spark streaming code on SBT windows using scalatest. sbt testOnly <<ClassName>> * * * * * * 2018-06-18 02:39:00 ERROR Executor:91 - Exception in task 1.0 in stage 3.0 (TID 11) java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream.(Ljava/io/InputStream;Z)V at org.apache.spark.io.LZ4CompressionCodec.compressedInputStream(CompressionCodec.scala:122) at org.apache.spark.serializer.SerializerManager.wrapForCompression

How to test that Akka actor was created in Scala

北慕城南 提交于 2019-11-30 12:46:22
I'm trying to write a test that will verify that my actor below is creating a heartBeatExpireWorker and a heartBeatAccepter, but I have no idea how to do it. First I was thinking I could use Mockhito mock or a spy in place of context and then verify that I called actorOf, but I can't figure out a way to inject the context without breaking the Akka testing framework. Then, I was thinking that I could send an Identify message to the workers to verify that they exist. But it occurred to me that that wouldn't work either because the Akka TestKit doesn't seem to create children actors of an actor