MSTest: test methods inherited from a class located in another assembly not found

I have the following problem. I have some unit tests implemented in someone else's assebly, which I refer to in my unit test project. Unit tests are implemented as abstract classes and must be inherited (and "activated" with it) in my unit test project.

When I inherit these classes in my project, the testing methods are visible to me. But for some reason they are not managed by Visual Studio. When I run tests with Galio Icarus, I see a message in which "Test ... cannot be found."

When I copy abstract test classes to my project, the tests are detected and run properly.

Do you know if there are any restrictions for methods that perform unit tests? It seems to me that the test execution has logic that not only searches for TestClassAttribute, TestMethodAttribute and so on, but also checks if the test implementation is running in the same assembly.

The implementation is as follows:

abstract class with test implementation in foreign assebly:

[TestClass] public abstract class GeneralGridTestsBase<T> where T : GridParamsBase, new() { [TestMethod] public virtual void GetCellSetItems_Unique_CellSetKeys() { // Test implementation } // Other tests implemented here } 

In my test project, I inherit an abstract class and expect the tests to be visible and β€œactive”.

 [TestClass] public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams> { } 
+4
source share
1 answer

I was able to replicate this and then fix it by overriding the virtual test method and calling the underlying implementation. It doesn't seem to be needed, but I guess it's just the idiosyncrasy of the MSTest framework:

 [TestClass] public class RetailInputGeneralTests : GeneralGridTestsBase<RetailInputParams> { [TestMethod] public override void GetCellSetItems_Unique_CellSetKeys() { base.GetCellSetItems_Unique_CellSetKeys() } } 
+3
source

Source: https://habr.com/ru/post/1387393/


All Articles