Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a class contains only tests with [Ignore], class cleanup runs but not class init #355

Closed
dee-see opened this issue Feb 1, 2018 · 3 comments
Labels
Help-Wanted The issue is up-for-grabs, and can be claimed by commenting Type: Bug

Comments

@dee-see
Copy link

dee-see commented Feb 1, 2018

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

  1. The class is not even instantiated and nothing runs
  2. 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

@jayaranigarg
Copy link
Member

@pvlakshm : Can you take this?

@jayaranigarg
Copy link
Member

jayaranigarg commented Feb 5, 2018

@dee-see : We acknowledge this to be bug on our end and we will be fixing this in our upcoming releases.
We would be happy to help you, if you would like to contribute a fix for the same.

@jayaranigarg jayaranigarg added the Help-Wanted The issue is up-for-grabs, and can be claimed by commenting label Feb 5, 2018
@acesiddhu
Copy link
Contributor

this is now fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help-Wanted The issue is up-for-grabs, and can be claimed by commenting Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants