scala - How to initialize shared variables before parallel test in scalatest -


i have scalatest codes following:

class mytest extends flatspec paralleltestexecution {        val testsuiteid: string = generatesomerandomid()       should "print test id" in {          println(testsuiteid)     }       should "print test id again" in {          println(testsuiteid)      } }  

the 2 tests cannot print testsuiteid generate before them. instead regenerate id , print it. understand because of paralleltestexecution extends oneinstancepertest, each test here runs on own instance , have copy of variable "testsuiteid".

but want fixed id test suite , each test case in suite have access fixed without modifying it. tried create fixed id in beforeall{ } still didn't work.

how should achieve want?

one way work around put shared state in sort of external object:

object suiteid {   lazy val id: string = generatesomerandomid() } 

admittedly hack, , wouldn't surprised if scalatest has way handle built-in unaware of.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -