Why does visual studio 2012 not find my tests?

后端 未结 30 3165
盖世英雄少女心
盖世英雄少女心 2020-12-07 10:51

I have some tests that use the built in Microsoft.VisualStudio.TestTools.UnitTesting, but can not get them to run.

I am using visual studio 2012 ultimat

相关标签:
30条回答
  • 2020-12-07 11:20

    Quick check list for solving some common test problems. Make sure that:

    1. Test class and test methods are public
    2. Test class has [TestClass] attribute
    3. Test methods have [TestMethod] attribute

    If this does not help, try cleaning, rebuilding solution and restarting Visual Studio.

    0 讨论(0)
  • 2020-12-07 11:20

    This is more to help people who end up here rather than answer the OP's question:

    Try closing and re-opening visual studio, did the trick for me.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-07 11:21

    I had same symptoms, but under different circumstances.

    I had to add one additional step to Peter Lamberg's solution — Clean your solution/project.

    My unittest project targets x64. When I created the project it was originally targeting x86.

    After switching to x64 all my unit tests disappeared.

    I had to go to the Test Menu -> Test Setting -Default Processor Architecture -> x64.

    They still didn't show up.

    Did a build.

    Still didn't show up.

    Finally did a Clean

    Then they showed up.

    I find Clean Solution and Clean to be quite useful at getting the solutions to play ball when setting have changed. Sometimes I have to go to the extreme and delete the obj and bin directories and do a rebuild.

    0 讨论(0)
  • 2020-12-07 11:21

    For Me the solution was just a little bit less complicated.

    I had just brought an existing solution on to my machine (cloned from gitHub) and we do not track the auto-generated .cs files that Visual Studio created. (For each feature file there is a .cs file with the same name)

    Opening the solution without having the associated .cs files actually allow me to navigate to the bound methods, so it appeared as if specflow was wired up properly, but I was not able to view the test names in the Test Explorer.

    For this problem simply excluding the feature files from the project and then re-including them, forced VS to regenerate these auto generated codebehind files.

    After that, I was able to view the tests in the test explorer.

    0 讨论(0)
  • 2020-12-07 11:23

    This sometimes works.

    Check that the processor architecture under Test menu matches the one you use to build the solution.

    Test -> Test Settings -> Default Processor Architecture -> x86 / x64

    As mentioned in other posts, make sure you have the Test Explorer window open. Test -> Windows -> Test Explorer

    Then rebuilding the project with the tests should make the tests appear in Test Explorer.

    Edit: As Ourjamie pointed out below, doing a clean build may also help. In addition to that, here is one more thing I encountered:

    The "Build" checkbox was unticked in Configuration Manager for a new test project I had created under the solution.

    Go to Build -> Configuration Manager. Make sure your test project has build checkbox checked for all solution configurations and solution platforms.

    0 讨论(0)
  • 2020-12-07 11:23

    These are all great answers, but there is one more reason that I know of; I just ran into it. In one of my tests I had a ReSharper message indicating that I had an unused private class. It was a class I'm going to use in an upcoming test. This actually caused all of my tests to disappear.

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