scalatest

How to show custom failure messages in ScalaTest?

家住魔仙堡 提交于 2019-12-02 17:22:15
Does anyone know how to show a custom failure message in ScalaTest? For example: NumberOfElements() should equal (5) Shows the following message when it fails: 10 did not equal 5 But i want more descriptive message like: NumberOfElements should be 5. You're the first to ask for such a feature. One way to achieve this is with withClue. Something like: withClue("NumberOfElements: ") { NumberOfElements() should be (5) } That should get you this error message: NumberOfElements: 10 was not equal to 5 If you want to control the message completely you can write a custom matcher. Or you could use an

How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?

爱⌒轻易说出口 提交于 2019-12-02 16:07:48
The stacktraces are truncated - e.g. they end with [info] ... Using last or changing traceLevel doesn't help - it simply prints the complete stacktrace of the sbt wrapper. This is testing with testng (also I believe using scalatest and sl4j) Using hints found in the documentation here : (quoted) You can configure the output shown when running with sbt in four ways: 1) turn off color, 2) show short stack traces, 3) full stack traces, and 4) show durations for everything. To do so you must pass a -o argument to ScalaTest, and after the -o, place any combination of: D - show durations S - show

What’s the difference between ScalaTest and Scala Specs unit test frameworks?

…衆ロ難τιáo~ 提交于 2019-12-02 13:56:05
Both are BDD (Behavior Driven Development) capable unit test frameworks for Scala written in Scala. And Specs is built upon may also involve the ScalaTest framework. But what does Specs offer ScalaTest doesn't? What are the differences? Bill Venners Specs and ScalaTest are both good tools with happy users, but they differ in several ways. You will probably want to pick one as your main testing tool in Scala, but need not give up the other because you can use pieces of both. If you like ScalaTest's FeatureSpec syntax and specs' Mockito syntax, for example, you can put both jar files in your

spark unit test framework examples OTHER THAN com.holdenkarau

老子叫甜甜 提交于 2019-12-02 13:05:58
I am trying to write test case of spark scala application code. So I am planning to use SharedSparkSession for this purpose. I've seen other framework such as com.holdenkarau but I am looking for any other alternative especially using SharedSparkSeesion . So I tried finding sample examples using this SharedSparkSession from the web, but I am unable to do so. If you have any example, please post. Spark own test framework can be used in Scala, SparkSession present there. Some dependencies have to be included, for Maven below, can be converted to Sbt. ScalaTest example: https://apache

Scalatest PlusPlay Selenium not able to resize a window

人走茶凉 提交于 2019-12-02 11:41:17
Been digging at this for a while, and I can't seem to find a way to resize a window using scalatest plus. The only method I've found searching online or the documentation at http://doc.scalatest.org/2.1.5/index.html#org.scalatest.selenium.WebBrowser is executeScript("window.resizeTo(700,700);") but that has been unresponsive to me (no errors, no nothing). Is there a method that covers this that I am missing? A brief sample of my code: import java.util.concurrent.TimeUnit import org.scalatestplus.play._ import org.openqa.selenium._ import com.sun.xml.internal.bind.v2.TODO import scala

How to cut a long ScalaTest spec to pieces

我们两清 提交于 2019-12-02 02:57:51
I'm testing a REST API, and the code goes like this: Setting up stuff, populating a database using PUSH calls Testing API a Testing API b ... The code is currently in one rather huge FlatSpec : class RestAPITest extends FlatSpec with Matchers with ScalatestRouteTest with SprayJsonSupport I would like to chop the "Testing API a/b/..." parts out, to have the code more manageable. Trying to do that seems like a no-no: what's the type of it - how to pass that on, etc. etc. So, what's the recommended way to go about such stuff. The a/b/... tests could be run in parallel, once the basic setup has

How to test a Try[T] with ScalaTest correctly?

百般思念 提交于 2019-12-01 16:50:30
问题 I have a method that returns a Try object: def doSomething(p: SomeParam): Try[Something] = { // code } I now want to test this with ScalaTest. Currently I am doing it like this: "My try method" should "succeed" in { val maybeRes = doSomething(SomeParam("foo")) maybeRes.isSuccess shouldBe true val res = maybeRes.get res.bar shouldBe "moo" } However checking for isSuccess to be true looks a bit clumsy because for Options and Sequences there are things like should be(empty) and shouldNot be

ScalaTest on sbt not running any tests

a 夏天 提交于 2019-12-01 16:22:18
I am trying to run my tests with: sbt and then test. My build.sbt looks like this lazy val scalatest = "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" lazy val root = (project in file(".")). settings( name := "highlight2pdf", version := "0.1", scalaVersion := "2.11.6", libraryDependencies += scalatest ) And i just put the example test on test/scala 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

Using JUnit @Rule with ScalaTest (e.g. TemporaryFolder)

末鹿安然 提交于 2019-12-01 15:43:57
I would like to be able to use JUnit rules such as TemporaryFolder or other TestRule s we have already developed in-house. What is the best method to accomplish that? I'm aware of JUnitSuite but it doesn't seem to pick up the @Rule annotation. I would like to use a different ScalaTest suite anyway. So my questions are: Are JUnit rules supported by a ScalaTest suit? If not, is there a library out there which would make using Junit TestRule s possible? If not, how to use JUnit TestRule s in Scala tests? Or is there a more appropriate Scala-specific approach for acomplishing what TemporaryFolder

How to use ScalaTest “contain allOf” on two lists?

泪湿孤枕 提交于 2019-12-01 15:37:34
I was looking for a ScalaTest matcher to check that a list contains all of the needed elements (given within another list), but that may also be others. contain allOf demands to get two fixed elements, for some reason, the rest as varargs. I can do a workaround like this, but it's tremendously ugly: val list = List(1,2,3,4) val wanted = List(1,2,3) list should contain allOf ( wanted.head, wanted.tail.head, wanted.tail.tail :_* ) // ugly workaround For giving a list as the match, there is contain theSameElementsAs . However, it does not allow extraneous elements to be in the probed value (I