Is there a way to chain two arbitrary specs2 tests (in Scala)?

Every now and then I run into a situation where I need to make absolutely sure that one test executes (successfully) before another one.

For example:

"The SecurityManager" should { "make sure an administrative user exists" in new WithApplication with GPAuthenticationTestUtility { checkPrerequisiteAccounts(prerequisiteAccounts) } "get an account id from a token" in new WithApplication with GPAuthenticationTestUtility { val token = authenticate(prerequisiteAccounts.head) token.isSuccess must beTrue myId = GPSecurityController.getAccountId(token.get) myId != None must beTrue myId.get.toInt > 0 must beTrue }

The first test will create the admin user if it doesn't exist. The second test uses that account to perform a test.

I am aware I can do a Before/After treatment in specs2 (though I've never done one). But I really don't want checkPrerequisiteAccounts to run before every test, just before that first test executes... sort of a "before you start doing anything at all, do this one thing..."

Anyone know if there is a way to tag a particular test as "do first" or "do before anything else?"

-------------Problems Reply------------

You can just add a "Step" in between tests to enforce some sequentiality:

"make sure an administrative user exists" in ok

step("admin is created".pp)

"get an account id from a token" in ok

You can also add sequential to your spec like, to sequential execution of tests.

class MySpec extends mutable.Specification {
sequential

// rest follows
behaviour one
behaviour two
}

Category:scala Views:0 Time:2018-08-08
Tags: scala specs2

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.165 (s). 11 q(s)