testfx icon indicating copy to clipboard operation
testfx copied to clipboard

(Assembly/Class)(Initialize/Cleanup) methods as independent entries in Test Explorer

Open Evangelink opened this issue 3 years ago • 5 comments

Summary

Consider AssemblyInitialize, AssemblyCleanup, ClassInitialize and ClassCleanup as specific "test case" so that they are displayed as specific items in Visual Studio Test Explorer. This would ease understanding issues on these steps.

Background and Motivation

Before MSTest v3, errors or warnings during the (Assembly/Class)(Initialize/Cleanup) were shown only in the logs (except for specific cases). Starting with MSTest v3, AssemblyInitialize messages/errors are associated with 1st test run for given assembly, AssemblyCleanup to last test run for the assembly, and similarly, ClassInitialize to 1st test run for given class and ClassCleanup for last test run for given class.

This new behaviour allows to not miss any issue but is not ideal, especially in a parallel run context where 1st/last test run could differ, causing different test to be marked as failed.

Proposed Feature

Consider these methods as specific, non-runnable, entries.

Alternative Designs

None

AB#2051873

Evangelink avatar Dec 21 '22 13:12 Evangelink

@Evangelink We're trying to upgrade to 3.0.x and this is causing issues for us. We start and stop SQL instances in our Assembly Initialize and Cleanup functions using SqlLocalDb via https://github.com/martincostello/sqllocaldb. Sometimes when we try to delete the instance it does not work because the "specified instance is currently in use" or other issues. We've done a good amount of debugging on our end and we believe it's a bug in SqlLocalDb where even trying to force delete an instance does not work as expected - https://github.com/martincostello/sqllocaldb/issues/74. Now that the errors cause failures in the test runs instead of just logging it would be too great of a flaky test problem to upgrade the package. Is there an option for Assembly Init and Cleanup to function similar to 2.0.x?

Cjewett avatar Jun 07 '23 04:06 Cjewett

Hi @Cjewett,

I am not aware of the behavior before MSTest v2.2.8 so I will need to investigate a bit.

As far as I understand, it seems normal to me that of the init or cleanup fails it causes an error. I'm wondering if it's not possible for you to do a try/catch inside the init/cleanup where you expect the exception to happen.

Evangelink avatar Jun 07 '23 05:06 Evangelink

@Evangelink The try/catch workaround is what I've done for now but I was hoping there was some assembly attribute trickery similar to TestIdGenerationStrategy or TestDataSourceDiscovery. Understood if it doesn't exist though.

Cjewett avatar Jun 07 '23 08:06 Cjewett

@Cjewett, there is nothing I am aware of but I need to understand what changed (and how) to decide if we simply document this change of behaviour or if we want to give some option.

Evangelink avatar Jun 07 '23 11:06 Evangelink

✅ Successfully linked to Azure Boards work item(s):

testplatform-bot avatar May 06 '24 11:05 testplatform-bot