mercredi 25 mars 2015

MSTest ignores test classes with non-test generic methods that have type constraints defined in a different assembly in .NET 4.5.1

I've been puzzling over this one for the past hour or so. I have an app and a set of unit tests that target Windows 8.1 / WinRT / .NET 4.5.1. All projects and the solution compile and link successfully, and the app runs successfully. The app contains a number of assemblies, two of which are described below.


Suppose assembly 1 contains the unit tests:



// assembly 1
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using NamespaceInSameAssembly;
using NamespaceInDifferentAssembly;

namespace Tests {
[TestClass]
public class DownloadTests {
[TestMethod]
public void Test1() {
int x = 2;
Assert.AreEqual(2, x);
}

private void HelperThatWorks1<T>() where T : IInterface1 { }
private void HelperThatWorks2<T>() where T : IInterface2 { }
private void HelperThatWorks3() {
IInterface3 x = null;
}
//private void HelperThatDoesntWork<T>() where T : IInterface3 { }
}
public interface IInterface1 {}
}

namespace NamespaceInSameAssembly {
public interface IInterface2 { }
}


And assembly 2 contains other, non-unit-test related stuff:



// assembly 2
namespace NamespaceInDifferentAssembly
{
public interface IInterface3 { }
}


If I execute Test1() using the MSTest runner, it runs successfully and the test appears in the Unit Test Explorer window. If I then uncomment HelperThatDoesntWork() and execute the test, the test doesn't run, and MSTest removes it from the Unit Test Explorer window.


The only difference I can see is that IInterface3 is defined in a separate assembly, although it's not clear to me why this would matter for generic type constraints but not references of that type.


Any ideas why this might be happening?


Aucun commentaire:

Enregistrer un commentaire