score:3
i am assuming dosomething()
performs some operation that is dependent on application state.
try this:
class applicationspec extends freespec with beforeandafterall with oneserverpersuite{
override protected def beforeall(): unit = {
dosomething()
}
"application test" - {
"first test" in {
...
}
}
}
the problem is you are possibly mixin linearization in wrong order
.
by mixin
oneserpersuite before beforeandafterall, the order in which the super.run()
is called is reversed, leading to beforeall()
being called before application start.
from the git repo of the two projects:
//beforeandafterall
abstract override def run(testname: option[string], args: args): status = {
if (!args.runtestinnewinstance && (expectedtestcount(args.filter) > 0 || invokebeforeallandafterallevenifnotestsareexpected))
beforeall()
val (runstatus, thrownexception) =
try {
(super.run(testname, args), none)
}
catch {
case e: exception => (failedstatus, some(e))
}
...
}
//oneserverpersuite
abstract override def run(testname: option[string], args: args): status = {
val testserver = testserver(port, app)
testserver.start()
try {
val newconfigmap = args.configmap + ("org.scalatestplus.play.app" -> app) + ("org.scalatestplus.play.port" -> port)
val newargs = args.copy(configmap = newconfigmap)
val status = super.run(testname, newargs)
status.whencompleted { _ => testserver.stop() }
status
} catch { // in case the suite aborts, ensure the server is stopped
case ex: throwable =>
testserver.stop()
throw ex
}
}
so by putting the oneserverpersuite
trait in the end, it will first initialize the application
, then call super.run()
which will call the run
method inside beforeandafterall
which will execute beforeall()
and then invoke super.run()
of freespec
which will execute the tests.
Source: stackoverflow.com
Related Query
- There is no started application when trying to use beforeAll in scalatest
- java.lang.RuntimeException: There is no started application error, when testing a class from scala worksheet
- "Error occurred in an application involving default arguments" when trying to use Scala's copy method
- org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException when trying to use scalatest with scalajs
- Trying to get ScalaTest working: "There are no tests to run" when doing "mvn test"
- Scala Play no application started when grabbing data sources from application.conf
- After upgrade to Play 2.5.0: java.lang.RuntimeException: There is no started application
- Idea 13 and Gradle when trying to use scala-compiler in the Scala facets does not find scala-library
- Akka BindException when trying to connect to remote actor: Address already in use
- Type mismatch when trying to use generic JdbcDriver usage in Slick / Scala
- Type error when trying to use mapped projection with Slick
- How to know when to use `a`, `an` or `the` in ScalaTest Matchers when asserting exceptions?
- Value not found error when trying to use type aliasing for Set in scala
- Is there a reason not to use SparkContext.getOrCreate when writing a spark job?
- Scala NoClassDefFoundError when trying to use jar
- How to avoid 'null' when use scalatest with before/after?
- Trying to use JavaFX with Scala; getting "Unable to construct Application instance: class javaFXTest.Tests$"
- Kafka Structured streaming application throwing IllegalStateException when there is a gap in the offset
- Parsing Data in Apache Spark Scala org.apache.spark.SparkException: Task not serializable error when trying to use textinputformat.record.delimiter
- ClassNotFoundException when trying to connect to a postgres database through a scala/spark application
- In scala, is there an idiomatic way to handle closing and reopening an underlying stream when trying to wrap it with other streams?
- When defining scalatest within sbt libraryDependencies, why does everyone use the "test" configuration?
- PlayFramework 2.4, Actor injection issue: There is no started application
- I am trying to use spring application context and spring di in my scala vaadin app, but can't get a datasource to be injected
- Why am I getting "Could not initialize class org.apache.logging.log4j.LogManager" when trying to use ScalaTest?
- Kafka transaction - skip one offset when the application stops and be started again
- Getting The entire node set is unreachable error when trying to connect to MongoDB with reactivemongo in my play2 application
- Is there any technical or architectural reason for trying to use special characters for method names in Scala?
- Scala cats: problem with implicits when trying to use `===` syntax for `Eq` trait
- ScalaTest in sbt: is there a way to run a single test without tags?
More Query from same tag
- Order of construction of nested objects and member variables
- Scala: Sequence difference
- Akka: how to get the results?
- How do I override default codec in circe?
- Why does the Scala compiler give "value registerKryoClasses is not a member of org.apache.spark.SparkConf" for Spark 1.4?
- How to include Streaming test jar in sbt build?
- No implicit view available from fastparse.P[Any] => fastparse.P[Unit]
- Change 'play dist' output file name via command-line
- Scala and HTML parsing
- Sort using apache spark for text input
- Queue asynchronous task in Play! - correct way
- How to convert RDD of JSONs to Dataframe?
- Pattern Match build multiple Seqs
- Scala ORM producing incompatible version build errors
- Scala use argument which is passed to construct the object in other method of the object
- How can I fix evicted libraries and ambiguous reference error in Scala (Akka 2.4.0)?
- check if all fields in object are null with Option
- How to launch locally built metals language server?
- Why is this call to implicitly ambiguous?
- Scala 2.12, instantiate type parameter?
- Cannot reference Java annotation in Scala class
- Basic repetition in scala
- How to merely stop child actors upon a parent's restart?
- Azure synapse equivalent commands
- How to convert a List to RDD with scala and spark
- How to use ForkOptions in SBT to change working directory for test within subproject?
- Best approach to reading Scala DSL code?
- Exception While Using net.alchim31.maven:scala-maven-plugin
- Represent postgres INET type in slick case class / table definition
- Fetching millions of records from cassandra using spark in scala performance issue