Triggering test run startup/cleanup logic through VS Code Test Explorer? #4080
Unanswered
peterinnesmsft
asked this question in
Q&A
Replies: 1 comment
-
Hi @peterinnesmsft I confirmed that if you're using sbt as a build server, sbt will invoke |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am looking for some guidance on executing test startup and cleanup logic/scripts/etc when attempting to run or debug tests through the Test Explorer view in Visual Studio Code.
For context, I am building an Apache Spark application with Scala. As part of this, my team and I are writing integration tests using the ScalaTest framework that allow us to spin up a Spark session locally at the start of the test run, execute our tests, and then stop the session at the end of the run. Currently, we are making us of sbt's Test.Startup and Test.Cleanup hooks in our project's build.sbt to execute this logic.
In other languages like C#/.NET, I've been used to having test assembly hooks that provide this kind of capability, but ScalaTest does not appear to have this, instead recommending using components like BeforeAndAfter traits on individual suites. Shutting down the Spark session after each suite isn't ideal, since it can be costly to keep restarting the session. Another option is to have some kind of wrapper suite, but then this means that every time we add a new suite, we need to ensure that it's added to the wrapper suite. I believe it also has the added side effect of impacting running a subset of tests using sbt's testOnly command. There's another option which would be to build our own custom test runner, but this feels pretty overkill. So after wading through these options, that's how I landed on using Test.Startup and Test.Cleanup hooks in build.sbt.
The problem this approach has is that, when attempting to run or debug tests using the Test Explorer view in Visual Studio Code, since it doesn't appear to run via sbt, we don't perform our test run startup/cleanup logic, which then causes errors when running our tests. We need an approach that will continue to work with sbt, since that is what our CI/CD pipelines use for running tests, but also a way in which it can be handled for manual running from our IDE.
I took a quick scan through the Metals documentation, but I didn't see anything obvious about how to do this. Are there any options or approaches that we can use to help support this kind of scenario? Any ideas or recommendations would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions