beforeAll() called only AFTER all tests

555 views
Skip to first unread message

Markus Kahl

unread,
Jun 7, 2014, 2:02:52 PM6/7/14
to scalate...@googlegroups.com
Hey,

I've got the problem, that beforeAll() is not called before all at all.
Here's how my codes looks:

    trait IntegrationTest extends BeforeAndAfterEach with BeforeAndAfterAll { self: Suite => ... }

    trait ApiSpec extends FunSpec with IntegrationTest with ApiAccess with Matchers { ... }

    class UsersSpec extends ApiSpec {
      describe("A") { ... }
      describe("B") { ... }
    }

Now when I run UsersSpec what I would expect is that #beforeAll() is called before A and B.
What happens, though, is that A and B are run and only after that is #beforeAll() called.

Am I doing something wrong?

~ Markus

Bill Venners

unread,
Jun 7, 2014, 5:56:57 PM6/7/14
to scalate...@googlegroups.com
Hi Markus,

The beforeAll code will execute before all tests. But in a FunSpec, tests are defined with it, not describe. Describe defines a "scope" that groups tests. The body of the describe clauses run when the test class is instantiated, so that happens first. Any it clauses that it contains will cause tests to be registered at construction time, but those bodies aren't executed until later when run is called. Later, when run is called, beforeAll will be executed before all of the tests. This is I think what you're looking for:


trait IntegrationTest extends BeforeAndAfterEach with BeforeAndAfterAll { self: Suite => ... }

    trait ApiSpec extends FunSpec with IntegrationTest with ApiAccess with Matchers { ... }

    class UsersSpec extends ApiSpec {
      it("A") { ... }
      it("B") { ... }
    }

Bill


--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com

Markus Kahl

unread,
Jun 7, 2014, 7:38:05 PM6/7/14
to scalate...@googlegroups.com
Hey Bill,

thank you for the explanation! Now I understand what my mistake was.

Best,
Markus
Reply all
Reply to author
Forward
0 new messages