scalatest

java.lang.NoSuchMethodError with Scala actors

99封情书 提交于 2019-12-11 17:55:03
问题 I have a simple Scala application (taken from here) which I want to test. The whole project is compiled successfully with SBT. However, when I launch the tests with sbt test I get the following error message: Could not run test ConnectionTest:java.lang.NoSuchMethodError: akka.actor.Props$.apply(Lscala/Function0;)Lakka/actor/Props; From the internet search, I get the impression that some of my versioning is not compatible but that is merely a guess. What may be wrong? [Test Case] import akka

Unit testing class that extends a trait - how do I mock and stub methods in the trait?

前提是你 提交于 2019-12-11 10:27:34
问题 I'm using scalatest to unit test a class that extends a trait (in the sense that my class is using the trait as a mixin). The trait contains methods that are helper methods (which ultimately call a few lookups in a database) which I would like to stub out so that I can isolate just the functionality of my class. But I havent been able to find a framework like Mockito or ScalaMock that makes that possible. Question: Can it be achieved with a mocking framework, and if so how? And if not, I'd be

How to do an instanceof check with Scala(Test)

大憨熊 提交于 2019-12-11 04:13:42
问题 I'm trying to incorporate ScalaTest into my Java project; replacing all JUnit tests with ScalaTests. At one point, I want to check if Guice's Injector injects the correct type. In Java, I have a test like this: public class InjectorBehaviour { @Test public void shouldInjectCorrectTypes() { Injector injector = Guice.createInjector(new ModuleImpl()); House house = injector.getInstance(House.class); assertTrue(house.door() instanceof WoodenDoor); assertTrue(house.window() instanceof BambooWindow

scalatest “A stack” should “do something” — wtf? How is should a method of string?

非 Y 不嫁゛ 提交于 2019-12-11 03:59:39
问题 I'm just starting out with scala here and I'm finding some of the syntax confusing. For example from the scalatest main page class ExampleSpec extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in {...} } As I read it that means "should" is a method of string "A stack"? If that is right, how does that happen? It doesn't seem to work from the scala prompt scala> class ExampleSpec { | "A Stack" should "pop values" | } <console>:9: error: value should is

Execute multiple Scalatests in sbt

谁说我不能喝 提交于 2019-12-11 03:52:26
问题 I have multiple IntelliJ (Scala) modules that have build.sbt file and scalatest code. I also created ScalaTest configurations for each of them. I can run the test one by one from the execution of sbt test . Is it possible to execute all the tests at once? I can think of making a Python/Bash script, but I wonder if there is a simple way to do it. for d in dirs: execute("sbt test") ADDED From Alexey Romanov's answer, I created a build.sbt in the root directory with the following content lazy

Comparison matchers fail on mixed numeric types

大兔子大兔子 提交于 2019-12-11 02:12:17
问题 In vanilla Scala the following assertions pass assert(1D > 0F) assert(1F > 0) assert(1L > 0) assert(1 > 0.toShort) assert(1.toShort > 0.toChar) however similar matchers in ScalaTest fail 1D shouldBe > (0F) 1F shouldBe > (0) 1L shouldBe > (0) 1 shouldBe > (0.toShort) 1.toShort shouldBe > (0.toChar) A workaround is to make both sides the same type, for example 1D shouldBe > (0D) Why does it work in Scala, but not in Scalatest, or what is it about the signature of > def >[T : Ordering] (right: T

Maven not discovering ScalaTest unit tests

岁酱吖の 提交于 2019-12-11 00:34:41
问题 I have the following unit tests: import org.scalatest.FunSpec import org.scalatest.Matchers._ class MyClassSpec extends FunSpec { describe("MyClass"){ describe("Scenario 1"){ it("Condition 1") { true shouldEqual false } it("Condition 2"){ true shouldEqual false } } } } When I run maven test, this compiles fine but the tests are not found. Here is the output: [INFO] --- maven-surefire-plugin:2.7:test (default-test) @ project-name --- [INFO] Tests are skipped. [INFO] [INFO] --- scalatest-maven

Scala Play Slick RejectedExecutionException on ScalaTest runs

与世无争的帅哥 提交于 2019-12-10 21:10:37
问题 My FlatSpec tests are throwing: java.util.concurrent.RejectedExecutionException: Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@dda460e rejected from java.util.concurrent.ThreadPoolExecutor@4f489ebd[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] But only when I run more than one suite , on the second suite forward; it seems there's something that isn't reset between tests. I'm using OneAppPerSuite to provide the app context. Whenever I use

Custom sbt task to run tests by tag

人走茶凉 提交于 2019-12-10 20:32:56
问题 I want to do some sbt custom tasks for running tests (scalatest) by tag. For example: now I can run this in the sbt console: sbt test-only -- -n UnitTests I want to run this doing something like sbt test-unit // or something like that I also want to do the same by excluding tests sbt test-only -- -l ExternalTests to: sbt test-exclude-external For accomplishing that I'm trying to create a custom sbt task... but i don't know how to do the -- -l stuff val testUnit = taskKey[Unit]("Launch unit

how to run scalatest at package level in Eclipse

时光总嘲笑我的痴心妄想 提交于 2019-12-10 20:08:13
问题 I'm using ScalaTest in Eclipse (Juno) with Scala 2.10, and the RunConfigurations window has the ability to run a test file, a test suite, or a test package. When I right click on a package name in the explorer window, there is an option to run the package (thereby running all the tests in that package). However, when I do that, no tests run and it displays this: WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all