MSTest: No tests are run because no tests are loaded or the selected tests are disabled

前端 未结 18 1590
不知归路
不知归路 2020-12-24 11:55

I have a c# solution with the following structure:

mySolution
  myProject
  myProject.MSTests
    References
      Microsoft.VisualStudio.QualityTools.UnitTe         


        
相关标签:
18条回答
  • 2020-12-24 12:05

    If your code is CLI (managed c++) and your test class inherits from an abstract base class, make sure that your test class implements the base's pure virtual method. if you didn't implement it, you may see the "no tests found to run" message.

    0 讨论(0)
  • 2020-12-24 12:07

    For posterity: I just found that marking tests as static made them silently fail to appear in the test list. Apparently that isn't allowed.

    0 讨论(0)
  • 2020-12-24 12:08

    I was making use of a public TestContext TestContext method to write to the test output and changed the scope to private. This made every test not discoverable. Changing it back to public helped.

    0 讨论(0)
  • 2020-12-24 12:09

    Another idea for the Googlers out there. My problem was trying to get ignored tests running again. Same MS error message occurs if you remove the Ignore label. Does not automatically re-enable the test. This article takes you through the last step. http://richallen.blogspot.com/2008/05/ms-test-re-enabling-ignored-tests.html

    0 讨论(0)
  • 2020-12-24 12:09

    I've just manually done this:

    Created a new C# class library project with the following code:

    namespace SO_Answer
    {
        public class Class1
        {
            public void Test()
            {
                var k = "Hello";
            }
        }
    }
    

    Saved the project and then went to 'File->Add->New Project' and chose 'Test Project'. After VS created the unit test project, I added a reference to the class library project I created earlier.

    In my test I have this code:

    namespace Unit_Test
    {
        /// <summary>
        /// Summary description for UnitTest1
        /// </summary>
        [TestClass]
        public class UnitTest1
        {
            /// <summary>
            ///Gets or sets the test context which provides
            ///information about and functionality for the current test run.
            ///</summary>
            public TestContext TestContext { get; set; }
    
            #region Additional test attributes
    
            // You can use the following additional attributes as you write your tests:
            // Use ClassInitialize to run code before running the first test in the class
            // [ClassInitialize()]
            // public static void MyClassInitialize(TestContext testContext) { }
            // Use ClassCleanup to run code after all tests in a class have run
            // [ClassCleanup()]
            // public static void MyClassCleanup() { }
            // Use TestInitialize to run code before running each test 
            // [TestInitialize()]
            // public void MyTestInitialize() { }
            // Use TestCleanup to run code after each test has run
            // [TestCleanup()]
            // public void MyTestCleanup() { }
            #endregion
    
            /// <summary>
            /// The test method 1.
            /// </summary>
            [TestMethod]
            public void TestMethod1()
            {
                var f = new Class1();
    
            }
        }
    }
    

    The only code I added was the a using statement and the var f = new Class1(); statement. Looking at the MSTest runner, I can see TestMethod1 appear.

    I can't think of a reason why your unit tests are not being picked up. The only time I've had this is because I was using the MSTest runner to try and view NUnit tests by mistake. Try starting from scratch.

    0 讨论(0)
  • 2020-12-24 12:09

    This must be a bug and is an absolute pain especially as you have to reenable every single test method individually. However a bit iof lateral thinking produced a better solution - rename the test class and rebuild. Then rename it back. Seems to work. Ooops - no it doesn't. Renaming the class works but when it's renamed back it reverts to the original settings. The trick is to close down Visual Studio and delete the .vsmdi (visual studio test meta data) file. This will be regenrated.

    0 讨论(0)
提交回复
热议问题