user1595472
user1595472

Reputation: 41

Visual Studio test discovery not picking up Test in a referenced DLL

I have a local nuget package which contains a single test. The test is decorated with [TestClass] and it's test method is [TestMethod].

The reason this is a nuget package is because this test will be brought in to any test projects in order to test that a t4 transform has occurred in the referenced assemblies. The t4 template generates classes dynamically and I want the test to run to verify the t4 template has been executed (using reflection to make sure the generated classes have the expected methods)

When I reference the nuget package, the Visual Studio Test Explorer never displays the test. I was under the impression that VS reflected over the types in the assemblies to build it's test list, but that seems to be an incorrect assumption.

Is there a configuration setting or something that I am missing in order to have the test discovered?

Thank you, Jason

Upvotes: 0

Views: 169

Answers (1)

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29976

Visual Studio Test Explorer can only run tests from multiple test projects in a solution and from test classes that are part of the production code projects.

There are two workarounds for your scenario:

  1. Run the test from command line.

  2. Instead of placing the generated dll file in the nuget package, placing the test class file in the "content" folder of the nuget package. This will add the test class file to your project when install the nuget package and then Test Explorer will detect the tests after building the solution.

Upvotes: 1

Related Questions