Steps to reproduce
Run the following test class, only ClassCleanup runs and there is a NullReferenceException.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
private static object Obj;
[ClassInitialize]
public static void ClassInit( TestContext context )
{
Obj = new object();
}
[ClassCleanup]
public static void ClassCleanup()
{
Console.WriteLine( Obj.GetType() );
}
[TestMethod]
[Ignore] // The only test in this class is ignored
public void TestMethod1()
{
Assert.AreEqual( 1, 1 );
}
}
}
Expected behavior
One of two scenarios
- The class is not even instantiated and nothing runs
ClassInitialize and ClassCleanup run
Instantiating the class but running neither ClassInitialize nor ClassCleanup could leave some undisposed class variables... Though I'm wondering as I'm writing this if that's a bad practice and should be handled by an IDisposable test class.
Actual behavior
Only the class cleanup is executed, resulting in a NullReferenceException in this example.
My real life scenario is that we have a class with several tests and the only tests that matches the TestCaseFilter in this build is [Ignore]d.
Environment
VS 2017 15.5.5
MsTest v2 1.3.0-beta2, 1.2 and 1.1.18
Steps to reproduce
Run the following test class, only
ClassCleanupruns and there is aNullReferenceException.Expected behavior
One of two scenarios
ClassInitializeandClassCleanuprunInstantiating the class but running neither
ClassInitializenorClassCleanupcould leave some undisposed class variables... Though I'm wondering as I'm writing this if that's a bad practice and should be handled by anIDisposabletest class.Actual behavior
Only the class cleanup is executed, resulting in a
NullReferenceExceptionin this example.My real life scenario is that we have a class with several tests and the only tests that matches the TestCaseFilter in this build is
[Ignore]d.Environment
VS 2017 15.5.5
MsTest v2 1.3.0-beta2, 1.2 and 1.1.18