I am using VS2012 (v110)
I create a simple dll application with only 1 function and a test project to test the dll function. I set up both projects to be debug builds for win32 and tried Clean and Rebuild both projects but I don't see any test to be run on the test Explorer windows.
I also reference Dll project in the test project already.
Why isn't there anything shown in Test Explorer windows?
Actually MSTest doesn't work with simple class library projects.
You will have to create a unit test project and place your tests there.
If you use other testing frameworks like NUnit, then you can use plain class library. You can then use NUnit to run the tests outside VS, or use tools like ReSharper to run those tests inside VS
It seems you have used some test frameworks other that MSTest. If you want to use Test Explorer for some other frameworks you should install its runner too. for instance NUnit needs to install its test adapter as and extension in VS.NET
see here for more.
You should be able to modify an existing class library project to get mstest to recognize it as a test project by modifying the ProjectTypeGuids in the .csproj file as detailed in this answer How to get VS2010 to recognize my mstests generated by SpecFlow? (Look for the answer that lists the specific guids and not the currently accepted answer which says to just create a new project.)
Have had a simular problem. Solved it. I have been adding tests project to my VS 2012 solution and tests were not appearing in Test Explorer. Problem was that test project was located in IIS inetpub\wwwroot folder which didn't have windows user rights to modify it. Adding solution folder Windows user rights to modify it solved issue. Tests are now visible in test explorer and able to be debugged. I assume that vstest.discoveryengine.exe process with is run by windows user was not having access to test project files
Related
I followed the tutorials in the docs for azure devops with regards to running Selenium tests as part of the build.
My local tests run fine with the browsers I have webdrivers installed for, but when the VSTest task runs, it doesn't unpack any tests from anything under NUnit attributes.
Now a few things to point out with my project structure:
The test project started out as a basic Visual Studio 2017 Unit Test template, with MS Test.
I preferred NUnit, so I am writing/rewriting the tests using that framework instead of the MSTest it was created with.
My current azure devops pipeline config:
Working local tests setup:
Now, I can easily add a new project using the NUnit template which for whatever reason allows the azure build to see these tests, but that causes my project structure to change and it defaults to netcoreapp2.1 instead of 4.6, and then the azure build can't find all sorts of stuff.
Please follow the below steps may it resolve your issue
There is no need to add TestAdapter.dll in Test files
uncheck "Test mix contains UI tests"
Select test platform using "version" as "Installed by Tools Installer"
or
You might need to search the test dll into $(System.DefaultStagingDirectory) folder. sometimes azure agent place the dlls in staging directory instead of defaultworkingdirectory.
When adding a new NUnit project by the visual studio template like so
It defaults the framework version to netcoreapp2.1
If I change this to my build framework (net461), although the build states the same "These dlls will be skipped" message, the NUnit3Adapter is somehow now recognized and picks up the NUnit tests:
I have NUnit and MsTest in one project. Solution is common for whole team and only I have crash. Building solution works well, no errors. While running NUnit test I get exception: IO exception cannot load Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0.
I have one way reference, UnitTest project has reference to main Web project.
To write new tests I can use only MsTest but I would like NUnit.
I tried:
removing this dll -> but it crashes msTest (I want to have both
franeworks)
Upgrading dll but it makes another error (mayby I
could drill deeper this idea)
run as Administrator
In tests, Set default
process architecture x64 or x86
upgrading NUnit, NUnit Adapter ->
makes errors, solution is a bit old and I cannot actually upgrade so
much.
It seems Solution while testing only NUnit, tries to use MsTest dll, problem occures only for me in team. I've downloaded Repo recently compare to my team. Mayby I have someting newer than others and it's incompatible? I have VS2017. However others have VS2017 too.
I am stuck, please help
Solved after seting 'Copy Local' = true
I'm putting together a new stack of unit tests to be run together as a CI job. I'm using vstest.console.exe instead of mstest.exe mainly for its ability to run tests from several frameworks, but right now the focus is a few xUnit dlls. The jobs are run as part of a Jenkins pipeline.
I have tested everything successfully on a couple of dev boxes, but annoyingly test discovery is not working on any of the CI build boxes so far. This is after the addition of the 0.99.8 xUnit test adapter vsix (also tested with 0.99.7). The xUnit dlls are being built against 4.5 with the 2.0.0.2378 beta nuget version of xUnit.
I have reproduced the symptoms with the simplest possible dll, with a single public test method, working fine on my own box, not working on any build boxes. The deployment enviroment is pretty straight forward, with a VS2012 install and the xUnit test adapter, on Windows 2012.
I have enabled the TpTrace logging via the vstest exe config files and everything looks fine. I guess I'm looking for a way to troubleshoot the issue further (maybe tracing for the xUnit discovery process) or a workaround the problem. I'd prefer to retain the use of vstest console for the simplicity of running several frameworks.
I have written up this issue via the xUnit codeplex site as well.
I've checked out this SO post but none of the suggested solutions make sense here.
It takes me quite some time to find the solution of how to use vstest.console.exe and xunit for VS2013, so I think it worth the time to explain here how I did for everyone...
The first step is to follow what is explained here to install the pre-release xunit.runner.visualstudio nuget package in the xunit projects that need it to be able to run the xunit test from Visual Studio.
Then, when you run your vstest.console.exe command, you MUST use the parameter /TestAdapterPath.
Your command line should look like something (the path toward the xunit adapter is here relative so, you could put it in absolute or adapt depending on the active directory):
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" c:\path\to\your\assembly.to.test.dll /TestAdapterPath:".\packages\xunit.runner.visualstudio.0.99.9-build1021\build\_common\"
edit: Because the adapter dlls are copied to the output folder, we could simplify the command line giving the path "." to the /TestAdapterPath option:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" c:\path\to\your\assembly.to.test.dll /TestAdapterPath:"."
For information, it works also with NUnit, nuget package NUnitTestAdapter and the command:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" c:\path\to\your\assembly.to.test.dll /TestAdapterPath:"."
OK so problem solved, but after some frustrating troubleshooting that I will cover in case its useful for someone. The problem was that xunit.execution.dll was not available in the same folder as the dlls containing tests. This is required for xunit discovery. I only got here by:
Setting HKCU\Software\Outercurve Foundation\xUnit.net\Visual Studio Test Plugin\MessageDisplay = Diagnostic (this should be possible via the runsettings file but is not being picked up, and not possible via the VS tools options xunit page because its failing to open)
vstest now spits out 'Skipping xunitTests.dll (no reference to xUnit.net)'
This message actually means that xunit.dll and xunit.execution.dll weren't found in the folder
Problem solved by making sure that dll gets copied into that folder on the build boxes.
I have a visual studio project. I later added a .cs file for testing and have added the appropriate 'using' statements and [Test] and [Testfixture] attributes. When I open the nunit gui application, however, it only accepts .dll, .exe, and .nunit files. I was wondering what exact steps I need to take to execute the tests I wrote. Is it possible to do so directly in visual studio?
You should add the NUnit dll as a reference on your project.
JetBrains' Resharper is able to run the tests inside Visual Studio. Read more about Resharpers unittesting here. JetBrains has also developed a line coverage tool: dotCover.
Right now, Resharper is the best solution.
Test Driven .Net is the best free solution I know of.
Visual Studio 11 will finally allow for 3rd part testing framework plugins.
I am working on a class library (DLL) project in Visual Studio 2008; programming in C#. In order to test my DLL I just created a second project that is a console application and in that project I can reference the first and run tests. Is there a simpler way of doing this? Can I just create another file within my class library project that has the tests in it and then somehow tell Visual Studio to run that file?
I know one way would be to add a text file to my project and then write my test code in JScript. Then in the Project settings on the debug menu I can tell it to Start External Program (JScript). Then, the name of my test file, test.js, goes in the Command Line Arguments box. But, I am wondering if there is a way to do it using C# code instead of JScript?
You could add a testing project to your current solution, then set that project as the startup project. Then, hitting F5 on your class library project will start your testing project.
Take a look at NUnit or other similar unit testing framework.
The "Team Developer" and "Team Suite" flavors of Visual Studio already have Microsoft's unit testing framework built in.
Create a unit test project for the class library by using the right-click "Create Unit Tests" in a class/method in the library. I would recommend downloading TestDriven.NET and using the right-click test runner in it.
Are you talking about unit tests? You can use something like nUnit or the built in testing framework that comes with Visual Studio. The simplest tests just require you to add some attributes to your test fixture and make an assertion like obj1 == obj2.
Checking out something like Test-Driven Development (TDD), Domain-Driven Development (DDD) or Behavioral-Driven Development (BDD) may be beneficial. I like to use nUnit with nBehave, myself.