https://kotlinlang.org logo
Title
d

dave08

03/07/2021, 2:03 PM
Is there a way to only enable a project extension if actually needed in one of the test classes being run? I need some testcontainers to come up but only for certain tests, and stay alive for other classes that might need them.
I guess one option could be to use an
object
as a listener and plug it into the test classes using it.
s

sam

03/07/2021, 2:41 PM
Yeah just add the listener to some specs. Where are you adding it atm
d

dave08

03/07/2021, 2:45 PM
On the project, since I don't want those containers to get destroyed and created for every test class
But I don't want to run all the containers when some test classes don't really need them
s

sam

03/07/2021, 3:01 PM
Do you need them on every test run
d

dave08

03/07/2021, 3:37 PM
Not all of them
s

sam

03/07/2021, 3:37 PM
I don't understand the requirement. If you start the test container at the project level it'll only be started once ?
d

dave08

03/07/2021, 3:38 PM
Like I have some tests that only need postgres, others that only need mysql, etc...
s

sam

03/07/2021, 3:38 PM
And you run them in separate jobs
d

dave08

03/07/2021, 3:39 PM
jobs?
s

sam

03/07/2021, 3:39 PM
Test runs
Do you do gradle test postegres and gradle test mysql
Do just one gradle test that does them all
d

dave08

03/07/2021, 3:42 PM
No, I usually run single classes in the IDE before/after making changes to code. Before a release, I then run them all.
s

sam

03/07/2021, 3:43 PM
And it's in ide that you don't wanna start them all but just the ones applicable to that test
d

dave08

03/07/2021, 3:44 PM
Yup
Saves development time
s

sam

03/07/2021, 3:44 PM
My phone is about to die but you could add tags to the spec classes and have an if statement in the listeners and only start them if the spec has the appropriate tag
👍🏼 1