.net core test not showing correctly in VS 2015 Test Explorer - unit-testing

I am trying to build unit tests for my dotnet core project using xunit following these steps outlined here https://xunit.github.io/docs/getting-started-dotnet-core.html
The problem I have is that any updates to the the unit tests are not reflected in VS 2015 Test Explorer. I have tried building the solution and then running the tests, but it's still not showing up or it's using the old build.
If I run the tests from the command line using "dotnet test", then everything works fine. When I go to the Test Explorer here after, it shows the updated and new unit tests. But I can't get the same to work in VS Test Explorer.
What I do now is, go to the command line, run "dotnet test", go back to VS and "Run All" from the Test Explorer to get the view updated with the new test results.
It seems that doing the build in VS and selecting "Run All" doesn't affect the assemblies used by the Test Explorer.
Can you help me get everything working from VS itself?
I am using Visual Studio 2015 Update 3.

Just ran into the same problem today: disable the test settings if you have any loaded. After that they started successfully showing up for me.

Related

Can't get XUnit tests working with Visual Studio 2017 RC

For the life of me I can't get unit testing working in Visual Studio 2017 from the new msbuild-based netcoreapp1.0 xunit project template.
The requirement is for unit tests to work both inside Visual Studio (for the devs) and from dotnet test on the CLI for the automated build process however, I can't get either working consistently.
Here is what I have tried:
In an existing solution, create a new project and select .NET Core > xUnit Test Project.
Build project from Visual Studio, default test appears and runs successfully, now run dotnet test from powershell prompt, get:
> dotnet test
Test run for D:\...\bin\Debug\netcoreapp1.0\MyProj.dll(.NETCoreApp,Version=v1.0)
dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Program'
Or dotnet test with csproj file:
> dotnet test MyProject.csproj
(same error as above)
> dotnet test ..\MySolution.sln
Couldn't find a project to run test from. Ensure a project exists in D:\...
Or pass the path to the project
If I add the xunit.runner.console or xunit.runner.msbuild nuget packages, it stops the unit tests working from inside Visual Studio.
How do I get both working at the same time?
Thanks!
The bug you're hitting is present in Preview 3 and fixed in Preview 4. They didn't escape the command line when executing it, and since dotnet.exe is installed into C:\Program Files\dotnet by default, it always fails.
If you want to continue to use Preview 3, the simplest work-around is to edit your system PATH environment variable, and replace C:\Program Files\dotnet with C:\Progra~1\dotnet.
I know this isn't a very good answer, but dotnet-test-xunit only support project.json files. VS 2017 forces you to switch to csproj files.
I found this on xunit twitter feed:
If you're trying use #xunit in VS2017 RC w/ .NET Core, remove dotnet-test-xunit and use xunit.runner.visualstudio 2.2 beta 4 instead.
With the latest RC.3 I was having issues with the tests not being discovered, and found out that when you run the built-in Test Explorer it says in the output that Microsoft.DotNet.InternalAbstractions 1.0.0 is missing. This was also issue in the previous versions of .NET Core, and the solution is the same, install the package from Nuget.

Visual Studio 2013 running unit test

I'm using Visual Studio 2013, and I have a legacy solution that I need to modify, containing a a console application and a unit test project.
I want to run the console application project, and while it's running I also want to run one of my unit tests.
I run my console application, but when I go to the test explorer to run my unit test, the option is grayed out.
why is this, and how can I run my unit test?
You don't mention why you want to do this, so I'll just answer blind.
If you run your console app without debugging, then you can run your unit tests at the same time.
To run without debugging, use Ctrl+F5 (DEBUG -> Start Without Debugging).
Alternatively, open your console app's project folder, go to the bin\Debug folder and double-click on <your_app>.exe.
FWIW it doesn't sound like a very good idea to do this. Unit tests are meant to be runnable completely separately from your application.

How to get Visual Studio Online test runner to run my specflow tests?

I have a project which builds and runs tests in Visual Studio Online. I recently added SpecFlow the the project and wrote a bunch of scenarios, some of which run against a LocalDb database. I was half expecting the tests to fail on VSO, but when I pushed the code up it ran all of my tests and they all passed. When I checked the logs it seems that my Specflow tests were not run.
Is there something I have to do to get the specflow custom tool which generates the actual unit tests to run as part of the build, so that VSO will find the tests after it has built?
Can I run what are effectively integration tests in VSO, creating and destroying databases in my tests?
Ok so this was a bit of a D'oh moment. VSOnline wasn't running my tests because Specflow was building NUnit test. Changing it to build MSTest tests meant that the generated files containing the tests had the correct attributes and VSOnline recognized them and so happily built and ran them.
And using the LocalDb during the tests was fine as well, all worked like a dream.

How can I disable code coverage / assembly instrumentation in Visual Studio 2012?

I have a project upgraded from Visual Studio 2010 to 2012 and the .testrunconfig file was included in the upgrade process.
I noticed that it was possible to click "Analyze code coverage" on any of the unit tests that I had run and it would correctly display the result. However, my test run configuration (originally from VS 2010) had code coverage disabled.
After doing a bit of research I learned that the VS 2010 configuration files have been deprecated and replaced by .runsettings files. It would appear that VS 2012 enforces assembly instrumentation by default which has a massive overhead associated with it.
Therefore, I would like to know how I can disable code coverage in VS 2012. Based upon my current findings it does not seem to be a trival task. One recent article I read had me creating an XML file manually and naming it "MYCONFIGURATION.runsettings" and manually manipulating XML attribute values.
Does anyone know how this should be done?
This is what I understand from your post:
You have a Test project with .testsettings file. You have not enabled code coverage in the test settings.
Code coverage instrumentation is not enabled by default in your scenario. Binaries will be instrumented if you do 'analyze code coverage' from VS.
Additional Info:
You can confirm that .coverage file is not generated by running the following command from visual studio developer command prompt:
vstest.console.exe /Settings:<your test settings file> test.dll
A coverage file will only get generated if you have enabled coverage in test settings.
Code coverage is only enabled through the Test Explorer using data driven adapters. The metadata for tests ran through the test explorer is almost completely different than that of tests ran straight from the unit test session window. Have you tried simply running it straight from the code (the MSTest gui bubbles) or from the unit test session window?

TFS 2010 Build Automation - Enabling Code Coverage

How do you enable code coverage for unit testing in TFS2010 automatic build?
In Visual Studio 2010 we enabled Code Coverage for our test projects (Test --> Edit Test Settings --> Local Test Settings --> enable Code Coverage and choose assemblies to run code coverage against).
Now this is working fine (we can read code coverage) when running from Visual Studio 2010 (Test --> Run --> All Test In Solution).
The problem is that no code coverage is reported in TFS 2010 when building.
Note that the test projects are used by the build controller but without any code coverage.
Is very important for us to enable code coverage together with unit testing.
I forgot to mention that the problem I'm encountering has to do with code coverage for a web application project.
At step:
Test --> Edit Test Settings --> Local Test Settings --> enable Code Coverage and choose assemblies to run code coverage against
when choosing assemblies you can choose the web application. I think that the problem is related to Path (the value under the Path column from wizard) which is the one from developer machine (http://localhost...). When building and deploying with TFS the build goes on one server and the deployment on another.
The question should be now: which path should be available in testsettings. The build path or the deployment path?
Currently I'm not at work and can't test my doubts.
I'll let you know as soon as I get in touch with TFS.
You need to tell the build server which test settings file to use. You will find this in the build settings under Process >2. Basic >Automated Tests >1. Test Assembly >TestSettings file.
Once you have that specified then the Code coverage should work.