vstest
vstest copied to clipboard
How to trigger re-discovery of tests in Visual Studio Test Explorer
Description
We have a custom Test adapter for VS that handles unit tests written in C++ via Catch2. We also use a VS extension to build all our projects via Fastbuild, which intercepts various Build menu commands triggered by Visual Studio and redirects them to run Fastbuild. I suspect test discovery is automatically triggered after every (successful?) build of each VC++ project normally, but with our setup, there is no way to re-trigger test discovery after we compile some of our projects. The only way to re-trigger is to restart Visual Studio after compiling the projects, and it will trigger a discovery the first time the Test Explorer window is shown.
Is there a way to send a message from our VS build extension when a project is compiled successfully, to the Test Explorer to trigger a new test discovery? Or Is there any way to make the system aware of the dll produced by the build and if its timestamp changes, trigger a test discovery?
Is there a way to manually trigger a test discovery for the whole solution again? I couldn't find anything in the Test Explorer UI / menus, but maybe there is a way to add a menu from our extension that could send a message to the Test Explorer to trigger this.
Out test adapter implements ITestDiscoverer for FileExtension .dll. I've seen some other old pages referencing ITestContainerDiscoverer, but this doesn't seem to be part of the current object model any more. This old TS test adapter looks like it provides a timestamp for each file, I assume that's used to determine if the test discovery needs to run again. https://github.com/brunolm/TSTestExtension/blob/master/TSTestAdapter/TSTestContainer.cs
Environment
PC, Visual Studio 2022 17.4.1
@AbhitejJohn I think this is more a question for your team.
@zedmilner: I think the part where Fastbuild intercepts build commands might be tripping the Test Explorer up. Is there a way you could also fake a build complete event using the VS build schematics once FastBuild is complete?
While implementing your own version of ITestContainerDiscoverer might be an option, that would clash with the default machinery we have to discover dll based test containers which seems to be kicking in on solution load.
@AbhitejJohn we have a callback when the Fastbuild completes so it is possible to call anything, but I don't know what to call exactly. Can you advise on any documentation or samples, or provide a short code snippet?
@AbhitejJohn @peterwald Could you follow-up on this issue?
I agree with @AbhitejJohn that the normal way to do this would be to implement ITestContainerDiscoverer. You may run into issues though if your tests are being discovered twice. Once via the build system output, and again with your custom discoverer. It might take some work to disable the build system discovery and only depend on your custom discoverer.
Hello folks, can we have a follow up on this? Right now only way that I found to force a re-discovery is to either change the last write timestamp of a file or deleting the TestStore folder from the .vs but the files from the TestStore are locked while the VS is open. Could we have an api where we could force the discovery?
The API you are looking for is to implement ITestContainerDiscoverer in VS and trigger the TestContainersUpdated event.
Can it be used with legacy VSIX projects or only with the new ones that are using the VS extensibility?
I believe it works the same way for both.