Execute code once before all tests are being started

87 views
Skip to first unread message

Florian Witteler

unread,
Sep 16, 2016, 10:44:15 AM9/16/16
to scalatest-users
Hi guys!

Is there a way to somehow access the "root-suite" and override its beforeAll method?
In my usecase I'd like to start a docker-container with a cassandra before all my tests run - whatever the sbt test command might be. (be it testOnly, test it:test etc.)

We found a workaround in the Suites class by putting multiple Specs into one Suites-collection.
class End2EndSuite extends Suites(new End2EndSpec) with DockerizedCassandra

The disadvantage with this approach is that we have to annotate the End2EndSpec with @DoNotDiscover to prevent the Spec being executed twice.
And you have remember to add the Spec to the Suites-collection.

I hope it's clear what I meant.

Any ideas?

Regards,
Florian

Bill Venners

unread,
Sep 16, 2016, 10:47:24 AM9/16/16
to scalate...@googlegroups.com
Hi Florian,

Do you need to do something afterAll as well? If not then you can just place the initialization code in an singleton object and refer to the object from the tests in such a way that you trigger the initialization code. It will be run just once per JVM instance, and run when it is first used.

If you need to run afterAll code, you may want (or you may want anyway) to look at the build tool. If you're using sbt, for example, it has a way to run some code before and after a run.

What it sounds like we perhaps need is a beforeRun and afterRun feature.

Bill

--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalatest-users@googlegroups.com
To unsubscribe from this group, send email to
scalatest-users+unsubscribe@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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



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

Florian Witteler

unread,
Sep 16, 2016, 11:02:57 AM9/16/16
to scalatest-users
Hi Bill,

thanks for your quick response!
We thought about the singleton-object as well but discarded that approach because we need to stop the docker-container after the tests ran.

I forgot to mention the sbt task on which the test run depends on in my question. We discarded that as well. I prefer the tests being able to run from within my IDE.

Great idea with beforeRun and afterRun. That would do exactly what we are trying to do!

Regards, Florian


Am Freitag, 16. September 2016 16:47:24 UTC+2 schrieb Bill Venners:
Hi Florian,

Do you need to do something afterAll as well? If not then you can just place the initialization code in an singleton object and refer to the object from the tests in such a way that you trigger the initialization code. It will be run just once per JVM instance, and run when it is first used.

If you need to run afterAll code, you may want (or you may want anyway) to look at the build tool. If you're using sbt, for example, it has a way to run some code before and after a run.

What it sounds like we perhaps need is a beforeRun and afterRun feature.

Bill
On Fri, Sep 16, 2016 at 7:43 AM, 'Florian Witteler' via scalatest-users <scalate...@googlegroups.com> wrote:
Hi guys!

Is there a way to somehow access the "root-suite" and override its beforeAll method?
In my usecase I'd like to start a docker-container with a cassandra before all my tests run - whatever the sbt test command might be. (be it testOnly, test it:test etc.)

We found a workaround in the Suites class by putting multiple Specs into one Suites-collection.
class End2EndSuite extends Suites(new End2EndSpec) with DockerizedCassandra

The disadvantage with this approach is that we have to annotate the End2EndSpec with @DoNotDiscover to prevent the Spec being executed twice.
And you have remember to add the Spec to the Suites-collection.

I hope it's clear what I meant.

Any ideas?

Regards,
Florian

--
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

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.

Florian Witteler

unread,
Sep 16, 2016, 11:08:02 AM9/16/16
to scalatest-users
This feature would save us lots of time in the end.
If you help pointing us in the right direction, we could work on that feature and submit a PR.

Regards,
Florian

Florian Witteler

unread,
Sep 20, 2016, 9:07:43 AM9/20/16
to scalatest-users
Hi!

We discussed this topic in greater detail. We came to the conclusion that we won't let our integrationtests boot up their environment. 
The coupling between code and the surrounding infrastructure is too high then. We will provide running containers before the integrationstests start.
And if we want to start our tests from within a docker-container we run into the docker-in-docker challenges.

So from our side there's no need for before- and afterRun.

Regards,
Florian
Reply all
Reply to author
Forward
0 new messages