scalatest

Can't run Scalatest with Gradle

不打扰是莪最后的温柔 提交于 2020-01-12 02:56:06
问题 task scalaTest(dependsOn: testClasses) << { description = 'Runs Scalatest suite' ant.taskdef(name: 'scalatest', classname: 'org.scalatest.tools.ScalaTestAntTask', classpath: sourceSets.test.runtimeClasspath.asPath ) ant.scalatest(runpath: sourceSets.test.output.classesDir, haltonfailure: 'true', fork: 'false') { reporter(type: 'stdout') } } I run gradle scalaTest and I get: * What went wrong: Execution failed for task ':scalaTest'. > java.lang.NoClassDefFoundError: scala/reflect/ClassManifest

How can a private class method be tested in Scala?

吃可爱长大的小学妹 提交于 2020-01-11 17:10:07
问题 I have a companion object with a private method, like so: package com.example.people class Person(val age: Int) object Person { private def transform(p: Person): Person = new Person(p.age + 1) } I would like to test this method, with something like: class PersonSpec extends FlatSpec { "A Person" should "transform correctly" in { val p1 = new Person(1) val p2 = Person.transform(p1) // doesn't compile, because transform is private! assert( p2 === new Person(2) ) } } Any help on having test code

How to use scalacheck prop generators in scalatest FlatSpec

风流意气都作罢 提交于 2020-01-04 16:58:10
问题 I'm trying to use the scalacheck property generators in a scalatest.FlatSpec test file. The test should fail and be reported by junit framework (and eclipse in my case) but the test pass and error is just displayed in console. import scala.collection.immutable.TreeSet import org.junit.runner.RunWith import org.raisercostin.namek.UnitSpec import org.scalatest.junit.JUnitRunner import org.scalatest.FlatSpec import org.scalatest._ @RunWith(classOf[JUnitRunner]) class SetsTest2 extends FlatSpec

How to use scalacheck prop generators in scalatest FlatSpec

烂漫一生 提交于 2020-01-04 16:57:05
问题 I'm trying to use the scalacheck property generators in a scalatest.FlatSpec test file. The test should fail and be reported by junit framework (and eclipse in my case) but the test pass and error is just displayed in console. import scala.collection.immutable.TreeSet import org.junit.runner.RunWith import org.raisercostin.namek.UnitSpec import org.scalatest.junit.JUnitRunner import org.scalatest.FlatSpec import org.scalatest._ @RunWith(classOf[JUnitRunner]) class SetsTest2 extends FlatSpec

Perform specialised functionality on failure of a Scalatest

守給你的承諾、 提交于 2020-01-04 09:15:34
问题 I am using selenium to perform integration tests on a Scala web app. I would like to either screenshot or print the html of a page into the console whenever a test fails. My current set up is Scalatest using Selenium 2.0, with Spec. Is there anyway to intercept a failure or determine the state of a test from a AfterEach override method? 回答1: To do that you'll want to override withFixture instead of using BeforeAndAfterEach. BeforeAndAfterEach's beforeEach method happens before the test, and

How to correctly use Spark in ScalaTest tests?

蹲街弑〆低调 提交于 2020-01-02 06:00:29
问题 I have multiple ScalaTest classes which use BeforeAndAfterAll to construct a SparkContext and stop it afterwards like so: class MyTest extends FlatSpec with Matchers with BeforeAndAfterAll { private var sc: SparkContext = null override protected def beforeAll(): Unit = { sc = ... // Create SparkContext } override protected def afterAll(): Unit = { sc.stop() } // my tests follow } These tests run fine when started from IntelliJ IDEA, but when running sbt test , I get WARN SparkContext: Another

How to correctly use Spark in ScalaTest tests?

独自空忆成欢 提交于 2020-01-02 05:58:48
问题 I have multiple ScalaTest classes which use BeforeAndAfterAll to construct a SparkContext and stop it afterwards like so: class MyTest extends FlatSpec with Matchers with BeforeAndAfterAll { private var sc: SparkContext = null override protected def beforeAll(): Unit = { sc = ... // Create SparkContext } override protected def afterAll(): Unit = { sc.stop() } // my tests follow } These tests run fine when started from IntelliJ IDEA, but when running sbt test , I get WARN SparkContext: Another

how to make scalatest generate html report through sbt

你。 提交于 2020-01-01 02:51:12
问题 The way to do this for specs2 based test in sbt is (testOptions in Test) += Tests.Argument(TestFrameworks.Specs2, "html") but how about scalatest? I've done lots of Google search, but cannot find a good explanation/solution. 回答1: so two things I need to do... I. use any scalatest artifact after 2.0.M5b. For me, I added this dependency, org.scalatest" %% "scalatest" % "2.0.M6" % "test->*" excludeAll ( ExclusionRule(organization="org.junit", name="junit") ) "test->*" is necessary, otherwise

java.lang.NoClassDefFoundError: scala/Product$class

半城伤御伤魂 提交于 2019-12-30 01:41:08
问题 I am new to scala and I am trying out few sample codes for testing. However I am facing some issues when I run the test code. When I run the test, I am getting an error [trace] Stack trace suppressed: run last test:executeTests for the full output. [error] (test:executeTests) java.lang.NoClassDefFoundError: scala/Product$class [error] Total time: 3 s, completed Feb 27, 2017 6:57:15 PM My code is as follows FilterChecks.scala class filterChecks extends FlatSpec { "Filter checker passed a

Comparing collection contents with ScalaTest

混江龙づ霸主 提交于 2019-12-30 00:29:09
问题 I'm trying to unit-test some Scala that is very collection-heavy. These collections are returned as Iterable[T] , so I am interested in the contents of the collection, even if the underlying types differ. This is actually two related problems: How do I assert that two ordered collections contain the same sequence of elements? How do I assert that two unordered collections contain the same set of elements? In summary, I'm looking the Scala-equivalent of NUnit's CollectionAssert.AreEqual