Reputation: 7745
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 ultimate.
I have a solution of two projects; One has tests, using Microsoft.VisualStudio.TestTools.UnitTesting
, [TestClass]
before the class, [TestMethod]
before the test methods and reference Microsoft.VisualStudio.QualityTools.UnitTestFramework
(version 10.0.0.0, runtime version v2.0.50727). I have tried dot-net framework 3.5, 4 and 4.5 others give a re-targeting error.
I have tried to build the solution and project. Test explorer has the message `Build your solution to discover all available tests. Click "run all" to build, discover, and run all tests in your solution.
So the question is: How to I get visual studio to find the tests?
Have also tried to follow this: http://msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx but with no success: I get stuck in section getting started, when asked to right click and select create tests
. There is no create tests
.
I have this test(it compiles, but does not show up in test explorer):
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace tests {
[TestClass]
public class SimpleTest {
[TestMethod]
public void Test() {
Assert.AreEqual("a","a", "same");
}
}
}
I have now discovered (see deleted answer below) that it is because it is on a shared drive, but I don't as yet know how to get around it. (something about the security setting maybe).
Upvotes: 224
Views: 120639
Reputation: 1139
We were using xunit and solution worked for me and the team was deleting the folder %TEMP%\VisualStudioTestExplorerExtensions
Read this thread.
Why is the Visual Studio 2015/2017 Test Runner not discovering my xUnit v2 tests
Upvotes: 0
Reputation: 3833
In my case, I had 3 test projects, created with Visual Studio 2017 (but I think it doesn't matter), and only two of them were discovered by the Test Explorer. I realized that the third project had a different version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework
dll.
I updated it in the NuGet Manager and the tests appeared.
Upvotes: 0
Reputation: 90
Visual Studio 2015 (v.14.....) - same problem here
Cause: Different versions of NUnit and NUnit Test Adapter In my case I had the latest versions of both NUnit (3.5) and NUnit Test Adapter but the Test Adapter was not the right one. For NUnit 3 and higher there is a NUnit3TestAdapter that must be used
Solution: Uninstalled the "faulty" NUnint Test Adapter and installed the UNit3TestAdapter v.3.5.0 (the latest now is 3.6.0 but didn't use it in order to keep it same as NUnit)
After Rebuild of the Solution Tests poped up :)
Upvotes: 0
Reputation: 1254
The simplest thing you can do is, just drag and drop those files from the File Explorer to the Test project. Build the project again, and you are good to go!
OR
Open the .csproj
file of your Test project in a text editor and manually include the file name to compile. Search for the Compile
tag in the file and add your file which you want to run.
<ItemGroup>
<Compile Include="TestSettings.cs" />
<Compile Include="TestLibrary.cs" />
<Compile Include="UnitTest1.cs" />
</ItemGroup>
Add the Compile tag for your file and save it. Now run the tests. Your file with unit test will be detected and run.
Upvotes: 0
Reputation: 1427
I read all the existing answers and found that my (xUnit) tests weren't being discovered because I had removed 'unused' references and more specifically, xunit.execution.desktop
. Re-installing the xUnit package fixed the issue in my case.
Upvotes: 0
Reputation: 2830
Adding my answer as this is the top result on Google for this.
I'm using Visual Studio 2015 and (unknowingly - I just ran Install-Package NUnit
) installed the NUnit3 package NuGet to my test project. I already had the NUnit Test Adapter extension installed, and my tests were still not showing up.
Installing the NUnit3 Test Adapter through Tools > Extensions and Updates fixed this for me.
Upvotes: 1
Reputation: 7745
The problem was that the test runner, is configured to not run tests from a remote drive. When I copied the project to a local drive it worked fine, but I needed it on a shared drive (can not remember why).
I read that it can be configured to work from a shared drive, but never got to do it as by the time I discovered the solution I had switched to MonoDevelop on Debian.
Upvotes: 0
Reputation: 2908
Tests do not like async methods. Eg:
[TestMethod]
public async void TestMethod1()
{
TestLib oLib = new TestLib();
var bTest = await oLib.Authenticate();
}
After doing this:
[TestMethod]
public void TestAuth()
{
TestMethod1();
}
public async void TestMethod1()
{
TestLib oLib = new TestLib();
var bTest = await oLib.Authenticate();
}
It saw the test.
Upvotes: 1
Reputation: 509
I was experiencing this issue many times when I try to build the solution in a different PC.
I am using NUnit and Specflow as well. By default My test project targets X86 But I have to change this to X64. Steps are 1. Test Menu -> Test Setting -Default Processor Architecture -> x64. 2. Clean Build 3. Build 4. If still tests didn't show up. 5. Go to Tools Extensions and Updates Then Install NUnit and Specflow libraries 6. Clean Build 7. Build
Then usually test will showed up in Test Editor.
Upvotes: 2
Reputation: 23831
In my recent experience all of the above did not work. My test method
public async void ListCaseReplace() { ... }
was not showing up but compiling fine. When I removed the async
keyword the test the showed up in the Test Explorer. This is bacause async void
is a 'fire-and-forget' method. Make the method async Task
and you will get your test back!
In addition, not having the Test project's configuration set to "Build" will also prevent tests from showing up. Configuration Manager > Check your Test to build.
Upvotes: 18
Reputation: 1885
After googling "visual studio can't see tests" it brought me here, so I thought I'd share my problem. I could build my solution, and the tests existed, but I could not see them! It turns our it was a quirk of the IDE, that caused the problem. See image below for an explanation and fix:
Upvotes: 0
Reputation: 18028
I had same issue, but a bit different.
I was using visual studio 2012. For some reason, only the tests of the initial generated file was running. But tests in another file were not running. Tried out different solutions posted here, did not work.
Finally I figured out that I had a private method in the test class which was the first method inside the class. I just moved the private method after a test method; so now, a method with [TestMethod]
attribute is the first method inside the class. Strange, but now it works.
Hope this helps someone someday.
Upvotes: 1
Reputation: 187
Since none of these answers deal with the cause I encountered, for this problem, I will add my answer here as well.
In my case, it was a copy pasting code problem. We had a TestProjectA
where there are specific type of tests that we want to pull out to its own test project - TestProjectB
. The problem now was that, while tests in TestProjectA
continue to show up just fine, the tests in the new TestProjectB
aren't showing up in VS Test Explorer - unless you specifically build TestProjectB
or manually right click on a test there and run it.
The cause was that in copy pasting the code over, some namespaces didn't get updated:
TestMethodA()
in TestClassA
in namespace TestProjectA.ModuleA
with filepath \TestProjectA\TestClassA.cs
TestMethodA()
in TestClassB
in namespace TestProjectA.ModuleA
with filepath \TestProjectB\TestClassB.cs
So visual Studio prints out a message in Output window that the TestId for these two are the same, and proceeds to show TestProjectA
and not TestProjectB
in Test Explorer due to the TestId clashing between the two projects. Correcting the namespace to TestProjectB.ModuleB
for \TestProjectB\TestClassB.cs
fixed the issue.
Upvotes: 0
Reputation: 1832
Another issue that may prevent tests from being discovered, usually with a message in the Tests output window like:
Failed to configure settings for runsettings plugin 'VSTest Run Configuration' as it threw following exception: 'An error occurred while parsing EntityName. Line 1, position 8.' Please contact the plugin author.
This can be caused by having characters in your path or file names that would need escaping to be parsed as xml. Specifically the & character, as < and > are not allowed in directory or file names. This causes the test discovery to fall over and not identify the tests, but I could still run the tests by hand using Resharper by clicking in the margin.
Upvotes: 0
Reputation: 179
I know this is an older question but with Visual Studio 2015 I was having issues where my newly created test class was not being recognized. Tried everything. What ended up being the issue was that the class was not "included in the project". I only found this on restarting Visual Studio and noticing that my test class was not there. Upon showing hidden files, I saw it, as well as other classes I had written, were not included. Hope that helps
Upvotes: 2
Reputation: 97
One issue I've run into repetitively is not running Visual Studio (explicitly) as Administrator on Windows 8+. I tried several of the suggestions listed, but they did not get the unit tests to appear until I ran VS 2013 as Administrator (even though my shortcut is set to open VS that way, either opening the solution file or sometimes clicking the shortcut it doesn't actually open as admin).
Upvotes: 0
Reputation: 38373
This problem seems to have so many different solutions may as well add my own:
Close Visual Studio
Rename C:\Users\username\AppData\Local\Microsoft\VisualStudio\12.0\ComponentModelCache to ComponentModelCache.old
Run Visual Studio and the component cache will be rebuilt.
Upvotes: 0
Reputation: 10602
I was experiencing the same issue in Visual Studio 2013 Update 4 on Windows 7 SP1 x64 using a test project targeting the "Any CPU" platform configuration.
The problem was that the test project was actually named "Tests" and would disappear the second time the project was (re)built.
After I renamed the project to "MyProject.Tests" for example, the tests no longer disappear.
Upvotes: 0
Reputation: 2469
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.
Upvotes: 228
Reputation: 1802
None of the solutions here helped me. The tests wouldn't be discovered for one solution whereas another solution referencing the same projects worked fine. I finally solved this by deleting the solutionname.v12.suo file.
Upvotes: 1
Reputation: 891
I was getting the error: "Failed to initialize client proxy: could not connect to vstest.discoveryengine.exe."
Try to run Visual Studio as Administrator. That worked for me.
There is another Stack Overflow post discussing this error, and the same solution works for them. The question remains why this works.
Upvotes: 6
Reputation: 189
It looks like NUnit Framework 2.6.4 does not work well with NUnit Test Adapter. In the website it mentions the test adapter will only work with NUnit Framework 2.6.3.
This was my problem: 1. I had downloaded NUnit and NUnit Test Adapter separately through Nuget in the VS2012. Somehow NUnit got updated to 2.6.4 Suddenly i did not see my test cases listed.
Fix:
Uninstall Nuget and Nuget Test adapter
a. Go to Tools> Nuget > Nuget Pkg manager > Manage Nuget Pkg for Solution
b. List installed packages
c. Click manage
d. Un-check your projects
Install NUnit Test Adapter including NUnit 2.6.3 Framework
Clean/Rebuild solution
Open Test > Test Explorer > Run All
I see all the test cases
Hope this helps
Upvotes: 1
Reputation: 2693
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.
Upvotes: 2
Reputation: 13399
Here's another one to add to the list based on user error/stupidity.... I tried various answers from this question and then realised my test project was unticked in the Configuration Manager (Build menu, Configuration Manager) so it wasn't being built >.<
Posting this in the hope it'll save someone wasting an hour or two as I just did!
Upvotes: 0
Reputation: 21
I encountered the same problem in VS2013 Ultimate. My problem was that I was creating a Windows Service and forgot to uninstall it. So the Service was running and VS couldn't access one of the DLLs which caused that the whole test suite wasn't loaded at all.
Upvotes: 0
Reputation: 6689
Visual Studio Professional 2012, update 4 here. Having Interop function definitions (DllImport/extern) in the same project as test classes confused Test Explorer. Moving Interop into a separate project, resolved the issue.
Upvotes: 0
Reputation: 1593
Check referenced assemblies for any assemblies that may have "Copy Local" set to "False".
If your test project builds to it's own folder (bin/Debug for example) and the project depends on another assembly and one of those assemblies in the References list is marked Copy Local = "False", the assembly cannot load due to missing dependencies and your tests will not load after a build.
Upvotes: 1
Reputation: 189
This one just bit me. I added a test to my project, but could not get it to show up in Test Explorer. My old tests all showed up. Finally, I realized I was only viewing a specific playlist, and I had not added the new test to the playlist. If you are using playlists, select "All Tests" and see if VS finds your tests and displays them in Test Explorer. Then you can add them to the desired playlist, too.
Upvotes: 0
Reputation: 386
I have Visual Studio 2012 and i couldn't see the Tests in Test Explorer,
So I installed the following: NUnit Test Adapter
That fixed the issue for me !
Upvotes: 32
Reputation: 13990
In My case it was something else. I had installed a package and then uninstall it and reinstall an earlier version. That left a residual configuration/runtime/asssemblyBinding/dependencyIdentity
redirecting in my app.config. I had to correct it.
I figured it out by looking at the Output
window and selecting "Tests
" in the drop down. The error message was there.
This was a pain... I hope it helps someone else.
Upvotes: 2