Org.scalatest: global setting (e.g. beforeAllSuites?)

I have a scala application with some test using org.scalatest. To test a test database, these tests need some global configuration (and break).

Please do not tell me that my tests should not fall into the database, and I should do it Java-DAO-Stub-WTF-Overkill-Way β„’ :-).

I run tests using SBT, which provides a way to execute code before and after the test:

testOptions in Test += Tests.Setup( () => println("Setup") ) testOptions in Test += Tests.Cleanup( () => println("Cleanup") ) 

Unfortunately, I cannot access the classes in question. It is not surprising that importing them into build.sbt does not work either.

Any ideas?

+9
installation sbt scalatest
Dec 13 2018-11-11T00:
source share
1 answer

You can use BeforeAndAfterAll or BeforeAndAfter , depending on your needs.

BeforeAndAfterAll:

A tit that can be mixed in sets that need methods, and after the package is executed. This feature allows you to run the code before and / or after all tests and nested sets of the package to work.

So, in this case, you would define MasterSuite, which contains all the other suites / tests that extend this feature.

BeforeAndAfter:

A value that can be mixed with sets that require code to be executed before and after each test runs. This trait facilitates the testing style in which binding objects stored in instance variables are replaced, replaced or reinitialized before each test or set.

+4
Dec 14 '11 at 10:59
source share



All Articles