Why does visual studio 2012 not find my tests? - c#

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).

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.

Please add the keyword public to your class definition. Your test class is currently not visible outside its own assembly.
namespace tests {
[TestClass]
public class SimpleTest {
[TestMethod]
public void Test() {
Assert.AreEqual("a","a", "same");
}
}
}

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.

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 !

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.

Since the project is on a shared drive as the original poster have indicated. VS.NET needs to trust network location before it will load and run your test assemblies. Have a read of this blog post.
To allow VS.NET to load things of a network share one needs to add them (shares) to trusted locations. To add a location to a full trust list run (obviously amend as required for you environment):
caspol -m -ag 1.2 -url file:///H:/* FullTrust
To verify or list existing trusted locations run:
caspol -lg

A problem I've found is that tests don't get found in the Test Explorer (nothing shows up) if the solution is running off a network drive / network location / shared drive
You can fix this by adding an environment variable.
COMPLUS_LoadFromRemoteSources and set its value to 1

I had the same problem.. In my case it was caused by a private property TestContext.
Changing it to the following helped:
public TestContext TestContext
{
get;
set;
}
After cleaning and building the solution (as described in #Ourjamie 's answer), the test methods in the affected test class were available in the Test Explorer.

I ran into the same issue while trying to open the solution on a network share. No unit test would be detected by Test Explorer in this case. The solution turns out to be:
Control Panel -> Internet Options -> "Security" Tab -> Click "Intranet" and add the server IP address or host name holding the network share to the "Sites" list.
After doing this, I recompiled the solution and now tests appeared.
This should be quite similar to the answer made by #BigT.

Quick check list for solving some common test problems. Make sure that:
Test class and test methods are public
Test class has [TestClass] attribute
Test methods have [TestMethod] attribute
If this does not help, try cleaning, rebuilding solution and restarting Visual Studio.

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.

I sometimes get the same symptoms.
What I did is:
1. Closed the Test Explorer window
2. Cleaned the solution
3. Rebuild the solution
4. Relaunched Test Explorer window from Test -> Windows -> Test Explorer.
And I got my test in Test Explorer window.

From menu bar on top...
Test -> Run -> All Tests
You may also view all tests from Test Explorer (Test -> Windows -> Test Explorer)
Further with VS 2012, if you miss out anything try searching it using Quick Launch bar on top right (Ctrl + Q) "Test"
Hope this helps.

I found the best way to troubleshoot this issue is to create a .proj msbuild file and add your unit test projects which you hare having an issue into this file and execute the tests using the command line version of mstest. I found a small configuration issue in my app.config which only appeared when running the tests from mstest - otherwise the test project built just fine. Also you will find any indirect reference issues with this method as well. Once you can run the Unit test from the command line using mstest you can then do a clean solution, rebuild solution and your test should be discovered properly.

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.

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 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

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.

I've updated VS 2012 to the Latest Update . ie visual studio update 3.
That fixed the issue for me.

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.

I had this problem when upgrading my solution from Microsoft Visual Studio 2012 Express for Web to Microsoft Visual Studio 2013.
I had created a Unit Tests project in 2012, and after opening in 2013 the Unit Test project wouldn't show any tests in the tests explorer. Everytime I tried to run or debug tests it failed, saying the following in the output window:
Failed to initialize client proxy:
could not connect to vstest.discoveryengine.x86.exe
I also noticed that on debugging the tests, it was launching an instance of Visual Studio 2012. This clued me into the fact that the Unit Tests project was still referencing 2012. Looking at the test project reference I realised it was targeting the wrong Microsoft Visual Studio Unit Test Framework DLL for this version of Visual Studio:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
I changed the version number from 11.0 to 12.0:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
I rebuilt all and this fixed the issue - all tests were found in the Test Explorer and now all tests are found and running perfectly.

Check that your test project is not set to Delay sign only in your project properties -> Signing. If it is, deselect it and do a clean rebuild.

I hit the same problem while trying to open the solution on a network share in VS2013 Ultimate.
I corrected the problem by turning on
Control Panel -> Internet Options -> "Security" Tab -> Click "Local intranet", click on sites and make sure "Automatically detect intranet network" is ticked.

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.

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.

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

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.

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.

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.

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.

Related

SpecFlow Test cannot be run with Playwright.NET

I created a specflow project using c# and playwright. No issues with the code, but the tests do not run When using test explorer on visual studio.
when i run the test, the results always say:
test not run
I installed the nuget packages for playwright and specflow and cannot see any errors. Are there any other components required for the test to run?
I m using playwright.net with c#
any advise would be appreciated
sample feature file:
Feature: feature example
#mytag
Scenario: Open test
Given the test page is open
When I navigate to the links page
Then I will see all the links
thanks
1- Are the tests ignored?
If you have r# Open one of the test files and check if there is a little gray eye-like icon to the left of test method declarations, if so, tests are ignored.
if not on r#, open vs text explorer and check if your tests are there, and if they are, there is something on the window that says they are ignored.
This weirdly happens when your file path is too long (i.e deep in the folder hierarchy, or maybe not so eep, but long folder and file names.
try to move you test project up in the folder hierarchy on the drive.
2- Do you have a test runner for the test framework? i.e nunit test runner?
If you don't see your tests on the test explorer at all, try installing test framework's runner as a vs extension.
Have you tried to move the solution upper in the directory hierarchy?
ie.
c:\projects\mycompany.projects.crmprojects.solution1\project1\testproject....\test.cs
becomes
c:\projects\solution1\project1\test.cs

Test explorer in VS2019 shows "No source available" for specflow tests

In vs2019 test explorer shows "No source available" for my specflow tests, so double click will not end up going to the actual specflow test (feature file).
Those unittests are generated through the "Specflow.Tools.MsBuild.Generation" nuGet package.
The feature.cs files are ignored by Git and are not part of my project file. I am able to run them and after build they are discoverable (through NUnit 3 Test adapter visual studio extension).
I've tried numerous solutions, as in:
- upgrading to sdk-style project (see https://github.com/techtalk/SpecFlow/issues/1457#issuecomment-491497035)
- creating whole new project (full framework)
Any help would be appreciated! Thnx in advance.
In my case the expired license of Resharper was the reason of this issue. I clicked the button Start evaluation period and then restart VS.

Visual Studio Debug Single Test

I use to be able to right-click in one of my test classes and select Debug Test which would run the single test. All of a sudden it says Debug Test(s) when I right-click and runs all my tests.
How can I debug just one test?
Thanks
Microsoft Visual Studio Community 2017
You can right click directly on your [TestMethod] and select "Run test(s)"/"Debug test(s)", or open the Test Explorer window (from the menu: Test -> Windows -> Test Explorer) and run test method from there (selecting a group or a single one).
PS: remember to put at least one breakpoint inside the test you want to debug.
Not sure why but I had to reinstall the NuGet Test packages and that seemed to fix it. Thanks Manuel for the help.

MSTest refuses to run 64-bit?

I am writing tests for an application using Outlook Redemption that absolutely must run 64-bit (it connects to windows MAPI and Outlook x64). Unfortunately, I cannot for the life of me make it run the test in 64-bit. I have tried using a .runsettings file (edited to indicate 64-bit) and a .testsettings file (also edited), and finally I have selected Test>TestSettings>Default Processor Architecture>64-bit, to no avail.
Every time, System.Environment.Is64BitProcess is false, and when I load the dll to connect to Outlook and MAPI I get the dreaded COM Exception: Wrong OS or OS version for application (Exception from HRESULT: 0x800401FA (CO_E_WRONGOSFORAPP)) which indicates that 64-bit Outlook is installed and the process trying to access it is 32-bit.
I have restarted VS 2012 after making settings changes as I have read somewhere that a restart may be necessary. Does anyone have any other suggestions? I could just write this as a console app that runs informal tests and reports their status, but my next step is to get these tests integrated into the automated build. Any help would be greatly appreciated.
Edit
Screenshot of Host Settings page in .testsettings
Experiment
Interestingly, I did a little experiment. I created a new solution with a single console app project. I put a public method in there that just returned true. When I ran the console app, and paused execution, I looked and indeed it is running 64-bit; no problem there. I then added a test project, created a single test which called the method. I also added var is64 = Environment.Is64bitProcess and put a breakpoint after it.
Predictably, without changing any options, is64 was false. I chose the 64-bit default architecture from the dropdown under test, then cleaned the solution, and ran the test again, same result, running 32-bit. I restarted VS2012, cleaned, built, same result. I created a testsettings file and referenced it in the Test menu, clean build, same, restart,clean, build same. I created a runsettings file, set <TargetPlatform>x64</TargetPlatform> , referenced that in the test menu, ran through it all again, and came up with the same results. QTAgent32.exe continues to run the process, and absolutely refuses to heed my demands that it run 64 bit.
I swear, if I have to delete QTAgent32.exe and rename QTAgent to that name, I will. I am not above cramming my wishes down the computers throat when it wants to be obstinate. Please, if you dont want to see me mistreat a workstation, someone show me what is going wrong. Think of the computers.
If you use VS2012, then you will be able to select your platform x64 through test settings as below;
In this example I am referring to .runsettings file.
the settings are
But if wish to run your test through command line you need to use vstest.console.exe instead of MSTEST as it doesn't support for x64 test.dlls
you will find vstest.console.exe at "C:\Program Files (x86)\Common7\IDE\CommonExtensions\Microsoft\TestWindow\"
Please note below steps
Open CMD
Navigate to "C:\Program Files (x86)\Common7\IDE\CommonExtensions\Microsoft\TestWindow\"
execute vstest.console.exe "C:\Projects\Test\Test.Automation.Specs.dll" /InIsolation /platform:x64
Note : Test.Automation.Specs.dll is your test project and you need to define full path
I hope this help
I ran into the same issue just now. Here are the steps you can follow to fix the problem.
Switch default processor architecture for unit tests from x86 to x64: Go to Test->Test Settings->Default Processor Architecture->x64.
Change the Build settings for the unit test project to x64.
Clean the solution then rebuild the solution. Your unit tests should now show up in the test explorer, and you should not run into this issue anymore.
References
Link to MSDN reference which explains how to resolve the issue.
This is a bit out of my scope, but the configuration settings for both projects are set correctly, right? You have them set to build for AnyCPU or x64?
Just trying to Occam's Razor it out... I know I've been frustrated too many times by configuration settings that VS just magically decides to change on me.

Visual Studio 2012 not building dependent projects

I just upgraded a VS2010 project to VS2012 and am now having a problem where dependent projects are not building on demand. For instance, say I have the following projects in my solution:
Library A
ConsoleApp 1
Where ConsoleApp 1 references Library A. If I change the signature of a method in a class in Library A and run ConsoleApp 1, there will be a compiler error due to ConsoleApp 1 not seeing my changes because running ConsoleApp 1 did NOT cause Library A to build.
If I manually build Library A, then manually build ConsoleApp 1, it works fine. However, I would expect that running ConsoleApp 1 should cause any dependent projects to be rebuilt before launching.
Could I have something configured incorrectly? Or is this a bug in VS2012?
Your symptoms sound very similar to those I experienced a while ago. Ensure that the projects are set to build with your current active solution configuration and active solution platform under Build->Configuration Manager.
Try by removing project references and adding them again (path to follow: References -> (right click) Add reference -> Solution -> Project). Before giving another try Save All. This is how I solved it.
This happens when the .suo file for the solution becomes locked and Visual Studio is no longer able to write to it. Another symptom of this problem is that you will see temp suo files being created next to the solution when you open it. Try closing Visual Studio and deleting all *.suo files in your working area. Then reopen Visual Studio and rebuild all. No need to manually rebuild your solution. This will fix the issue when it is caused by a locked .suo, as happened to a colleague of mine today.
In his case, the cause seemed to be that he shutdown his laptop while Visual Studio was still open. Maybe the shutdown of Windows didn't complete cleanly? We can only speculate on how the .suo originally became locked.
I tried all the solutions above and that did not fix the issue for me. I found that it was because of the Active configuration in the ConfigurationManager was set to build only the Main (start up) project.
Go to Build > ConfigurationManager
Ensure that all the projects you want to build are checked as in the screenshot below
This is a similar issue on Asp.Net forum here and this is the details on MSDN
. Although it was weired, bcoz I never changed these settings and it was working properly last week
I've encountered a similar problem, the solution (or the probelem) were the Build and Run settings under Tools > Options... > Projects and Solutions > Build and Run where "Only build startup projects and dependencies on Run" was checked. The screenshot shows my currently working solution.
For me, I resolve the issue by right clicking on the project; Build Dependencies > Project Dependencies. Then manually setting the order for each project. very painful if you have a lot of projects.
make sure that the referencing project has same or higher .Net framework version than the referenced project.
Right Click solution in solution explorer then click "Clean Solution".

Categories