scalatest

Verifying by-name parameters in Mockito

我与影子孤独终老i 提交于 2019-12-10 19:28:38
问题 Given class UnderTest { def f(arg1: Int)(arg2: => Int) = ??? } Trying do do this: import org.mockito.Matchers val objUnderTest = mock[UnderTest] verify(objUnderTest).f(Matchers.eq(1))(Matchers.any()) fails with an "Invalid use of argument matchers!" exception, complaining that 2 matchers were expected, 1 was recorded. Is using Mockito to verify calls to functions with multiple argument lists including by-name parameters possible? 回答1: To my knowledge you can not mock byname parameters with

Can ScalaTest detect timeout without synchronization calls (like in an infinite loop?)

怎甘沉沦 提交于 2019-12-10 17:57:07
问题 In a following code the test called sleep fails gracefully, while the test freeze causes the testing to never end. import org.scalatest.FunSuite import org.scalatest.concurrent.TimeLimitedTests import org.scalatest.time.SpanSugar._ import scala.language.postfixOps class MainTest extends FunSuite with TimeLimitedTests { def timeLimit = 1 second test("sleep") { Thread.sleep(10000) } test("unintentional freeze") { var i = 100 var j = 0 while (i>0) { i += 1 // a bug: should be j += 1 i -= 1 } } }

How to set the PermSize for scalatest-maven-plugin?

寵の児 提交于 2019-12-10 17:08:25
问题 We're using scalatest-maven-plugin to run some spark tests, and the default perm size is around 80M, which is not enough, so we often got "OutOfMemoryError: PermGen". I tried to give it a bigger size, but not found how to configure it 回答1: You could use argLine config parameter as documented here http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin <plugin> <groupId>org.scalatest</groupId> <artifactId>scalatest-maven-plugin</artifactId> <version>1.0</version> <configuration>

ScalaTest can't verify mock function invocations inside Future

[亡魂溺海] 提交于 2019-12-10 16:38:17
问题 I'm trying to use Scala's Future together with ScalaTest and Mockito, but with a very simple test case, I'm not able to verify any of the invocations on a mocked function inside the Future. import org.mockito.Mockito.{timeout, verify} import org.scalatest.FunSpec import org.scalatest.mockito.MockitoSugar import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class FutureTest extends FunSpec with MockitoSugar { it("future test") { val mockFunction = mock[() =>

Failing to inject Play's WSClient instance using injector

♀尐吖头ヾ 提交于 2019-12-10 16:37:22
问题 I have a Class that has a WSClient dependancy injected: @Singleton class MyApiService @Inject() (wsclient: WSClient, conf: Configuration) { ... } and when running test and creating instance of MyApiService using injector : class MyTest extends FreeSpec with OneAppPerSuite with ScalaFutures with WsScalaTestClient { implicit lazy val materializer: Materializer = app.materializer lazy val wsc: WSClient = app.injector.instanceOf[WSClient] lazy val conf: Configuration = app.injector.instanceOf

ScalaTest test name without fixture?

為{幸葍}努か 提交于 2019-12-10 15:54:38
问题 First off, I saw it and this other post sounds exactly like what I need except for one thing, I can't use fixture.TestDataFixture because I can't extend fixture.FreeSpecLike, and I am sure that there must be some way to get the test name in a way that looks more like this (imagined code that doesn't compile) class MySpec extends FlatSpecLike with fixture.TestDataFixture { "this technique" - { "should work" in { assert(testData.name == "this technique should work") } "should be easy" in { td =

Running tests from jar with “sbt testOnly” in SBT?

佐手、 提交于 2019-12-10 13:31:45
问题 As part of a CI setup the very first step is to create a package/jar using SBT dist . The following steps are to run unit, integration and functional tests with the dist -created jar. Is it possible to do that with SBT? Normally I use sbt testOnly "Unit.*" , but that works in the context of a project. I can't find any documentation showing how to do this when there is already a jar. I'm using ScalaTest and I know there is a runner for it I could use http://www.scalatest.org/user_guide/using

Field inside object which extends App trait is set to null. Why is that so?

不羁的心 提交于 2019-12-10 12:53:03
问题 I'm trying to use scalatest to test an App like this: object Main extends App { val name = "Greg" } class JunkTests extends FunSpec with MustMatchers { describe("Junk Tests") { it("Junk-1 -- Must do stuff") { println("Name: "+Main.name) // some test here } } } My name output is always null. How can I get my main object going to use its facilities during a test? In actual use I have an App that's an Http server and I want to send it messages, but right now its never initialized so the server

Is there anyway we can give two conditions in Scalatest using ShouldMatchers

自作多情 提交于 2019-12-10 11:15:29
问题 How can I do something like this? Check for two conditions while testing // b is Option[Array[Int]] b should be ('empty) || b.get should be ('empty) I want to do it using ShouldMatchers instead of assert, since ShouldMatchers is part of scalatest. 回答1: You should be able to do val b: Option[Array[Int]] = ??? b should (be ('empty) or be (Some(Array.empty[Int])) See this section of the scalatest manual: Logical Expressions 来源: https://stackoverflow.com/questions/27964790/is-there-anyway-we-can

Scalacheck won't properly report the failing case

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 02:23:09
问题 I've wrote the following spec "An IP4 address" should "belong to just one class" in { val addrs = for { a <- Gen.choose(0, 255) b <- Gen.choose(0, 255) c <- Gen.choose(0, 255) d <- Gen.choose(0, 255) } yield s"$a.$b.$c.$d" forAll (addrs) { ip4s => var c: Int = 0 if (IP4_ClassA.unapply(ip4s).isDefined) c = c + 1 if (IP4_ClassB.unapply(ip4s).isDefined) c = c + 1 if (IP4_ClassC.unapply(ip4s).isDefined) c = c + 1 if (IP4_ClassD.unapply(ip4s).isDefined) c = c + 1 if (IP4_ClassE.unapply(ip4s)