Can I access the TestContext in the AssemblyCleanup method?

In the Microsoft UnitTesting namespace ( Microsoft.VisualStudio.TestTools.UnitTesting ) there are AssemblyInitialize and AssemblyCleanup attributes that you can apply to static methods, and they will be called before and after all tests, respectively.

 [AssemblyInitialize] static public void AssemblyInitialize(TestContext testCtx) { // allocate resources } [AssemblyCleanup] static public void AssemblyCleanup() { // free resources } 

My question is: is it possible and safe to access TestContext inside AssemblyCleanup() ? If not, stores resource references as static members as a reasonable alternative or can cause problems?

Additionally / optional: what is explained by the fact that you do not pass a reference to TestContext methods for cleaning?

+4
source share
2 answers

I am accessing a static property in one class and it seems to work fine. I will update this answer if I have problems. However, I do not get access to TestContext , so I wonder if this works too.

+1
source

You cannot pass any parameters to the AssemblyCleanup method. Here is the error if you try to do this:

Results message: SomeNamespace.TestDatabaseInitializer.AssemblyCleanup method mistakenly signed. The method must be static, public, does not return a value, and must not accept any parameters.

0
source

All Articles