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
Quick check list for solving some common test problems. Make sure that:
public
[TestClass]
attribute[TestMethod]
attributeIf this does not help, try cleaning, rebuilding solution and restarting Visual Studio.
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.
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.
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.
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.
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.