junit - moving from Java/Junit4 to Scala/ScalaTest -


i have questions regarding scalatest:

how can ensure test-execution order scalatest, can continue use junit4's @suite.suiteclasses annotation or there way without using junit @ all?

@runwith(suite.class) @suite.suiteclasses({     firsttest.class, secondtest.class   }) public class mytestsuite {   @beforeclass   public void setup() {     public mydb db = new db("config");   } } 

can translate above scala , ready go?

another question is:
how can make "db" field available suite-classes? in java field static reference suite-classes.
maybe define companion object holds reference?

in scalatest suite can contain 0 many tests , 0 many nested suites. suite's nested suites provided nestedsuites method, , names of tests run provided testnames method. general answer built-in scalatest style trait, order of nested suite , test execution determined order of show in return value of nestedsuites , testnames. if you're not otherwise getting order want, can override either or both of methods.

however, test order easier use 1 of traits in tests functions, because traits run tests in order appear in source. (by contrast, suite runs tests in alphabetical order test name.) i'd suggest use funsuite starters. example:

import org.scalatest.funsuite  class mysuite extends funsuite {   test("this 1 run first because appears first") {     // ...   }   test("this 1 run second because appears second") {     // ...   }   test("this 1 run third, , on") {     // ...    }  } 

as far getting suites run in order, that's more done because people use discovery find new suites written. way override nestedsuites. in 1.5 there suites class convenient way that:

import org.scalatest.suites  class mysuites extends suites(   new myfirstsuite,   new mysecondsuite,   new mythirdsuite,   new myfourthsuite ) 

then run mysuites , run nested suites in order declared them.


Comments