VSTS build of .NET Core 1.0 VSTest Warning: No test is available - asp.net-core

I recently switched all of my unit tests over from xunit to mstest, and on my local dev machine everything works great, but when I try to run my tests using a CI build in VSTS, it doesn't recognize any tests in my test dll, stating:
"Warning: No test is available in
c:\vsts_work\4\s\test\UnitTests\bin\Release\net452\UnitTests.dll".
I believe I have all of the important project.json bits in place:
"testRunner": "mstest",
"dependencies": {
"dotnet-test-mstest": "1.0.1-preview",
"MSTest.TestFramework": "1.0.1-preview"
}
Of note, I am using an on-premise build agent, but I've proven I can log into that build agent using the service account under which the agent runs, and I can open visual studio and run the tests that way.
Also, while one could contrive it by looking at the above path, it is worth explicitly noting that I'm using the full framework.
Hoping someone out there has already conquered this one.

I figured out how to use the "Visual Studio Test" action, thanks to this stackoverflow post
The only thing that answer lacks is how to make it work in VSTS (the answer provides the command line). To get it to work in VSTS, I put the following string in the "Test Assembly" parameter
**\test\**\project.json
And then put the rest of the command line arguments under "Advanced Execution Options" in the "Other console options" box.
/UseVsixExtensions:true /logger:trx
Hope this helps the next guy who is trying to stick with the visual studio tooling.

To run a .NET Core test during the build, you can add a "Command Line" task to run "dotnet test" command and set the "Working Folder" to the path where the "project.json" file placed:

I had a similar problem, getting the "Warning: No test is available" issue when I was looking right at the tests in Visual Studio.
It turns out the tests were trying to run in x86 when the application is 64 bit.
I recommend going to the Test menu at the top of Visual Studio, and open
Test>Test Settings>Default Processor Architecture>
and make sure the tests are on the right architecture, if you have a similar problem and the other answers aren't helping.

Related

Where is FrameworkUap10 used in VSTest.Console.exe for Win Universal Apps Unit testing

I've been tasked with adding Unit Testing to our WinUA. The developer said he added a new unit test for UWP project to his solution and I'm to add calling this at build time. He wasn't sure how to do it and pointed me to this article: Set up automated builds for your UWP app
I've added a "Visual Studio Test" step and set the following:
Test Assembly = **\*.UnitTests.build.appxrecipe
Other console options = /framework:FrameworkUap10
Running it throws the following error:
[error]Error: Invalid .Net Framework version:FrameworkUap10. Supported .Net Framework versions are Framework35, Framework40 and Framework45.
If I remove the invalid framework, no error is thrown but also no tests are run.
I cannot find any information on the /framework:FrameworkUap10 option. Searched MS, here and web and all that comes up is its use in this article... nothing about installing it on the build machine.
How does one install FrameworkUap10?
I was able to get this to work using the following using the following msbuild args for the msbuild step:
/p:AppxBundlePlatforms="$(BuildPlatform)"
/p:AppxPackageDir="$(Build.BinariesDirectory)\AutoBuildPackages\"
/p:AppxBundle=Always
/p:UapAppxPackageBuildMode=StoreUpload

Xunit not working using Visual Studio Team Services Build VNext

After following several blogs detailing how to get xUnit working with Team Services Build vNext:
http://tech.trailmax.info/2014/01/run-xunit-in-hosted-team-foundation-service/
Running unit tests in TFS/VSO Build vNext using xUnit adapter
http://www.donovanbrown.com/post/2015/06/15/how-to-run-xunit-test-with-vnext-build
None of which worked for me. From examining the build logs I get the following warnings for each of my test assemblies.
--------------------
Warning: [xUnit.net 00:00:00.1644156] Exception discovering tests from CHO.SAM.Business.Test: System.BadImageFormatException:
Could not load file or assembly 'c:\_Work\473cef3c\CHO\CHO.ALL\Tests\CHO.SAM.Business.Test\CHO.SAM.Business.Test\bin\Debug\xunit.execution.desktop.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
--------------------
Has anyone seen this before? and if so did you figure out a solution?
My thoughts are; my test projects are compiled using .NET Framework 4.6, I was wondering if this could be causing the problem? If so I would have to move over to nUnit or something as I don't feel it's right to change the compilation just to use a single test framework.
Add "/Framework:Framework45" to "Advanced/Other console options" (to run under .NET 4.5)
or
Add "/Framework:Framework40" to "Advanced/Other console options" (to run under .NET 4.0)
or
Change "Advanced/VSTest version" to "Visual Studio 2013" (to run under .NET 3.5)
This error is normally caused by a x64 compiled assembly running on x86 test runner or vice versa. Check the solution build configuration that is being run.
I had this same issue. Adding a UI test did not fix it for me. I found two alternatives that work:
use .net 4.5
OR
Set the advanced options of the VSTest task to use 2013 instead of 2015.
Hopefully this will be fixed soon.
In the end, I added a Visual Studio Coded UI test project and removed all it's contents (a class), it's empty!
I'm assuming it's added a reference or something that the build server felt it needed.
I am now getting my unit tests discovered, running and with code coverage.
Wierd!
It works, but I don't know why...
I ran into this issue when using a .Net Core class library to run my xUnit tests against a .Net Core Web Project (.Net Framework). What solved the issue for me was to change the default processor for running test to X64 in VS2015 via:
Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64
This solution was posted by #RehanSaeed here https://github.com/dotnet/cli/issues/3103

ShimNotSupportedException when running tests from MSTest or Resharper

I am currently working with Microsoft Visual Studio 2012 and the new Fakes framework. And after adding my unit tests to the MSBuild and continuous integration process, the Fakes unit tests happen to raise a ShimNotSupportedException.
I tried different stuff and read into that issue and found out that, this only happens when I run my tests from the Resharper feature, or directly in the code with MSTest. These exceptions DO NOT occur when running from the Test menu bar, which made me think about checking the setting files of this features.
After further research I found some articles where it says that it might has something to do with the code coverage setting specified in the Resharper or MSTest settings and if you switch that off, it solves the issue. ShimNotSupportedException in MS VisualStudio 2012 also relates to that problem.
I also found some input on the MSDN about that issue, which confirmed me that it has to do something with the code coverage: http://social.msdn.microsoft.com/Forums/en-US/vstest/thread/17fcfdc6-1cda-4692-a242-656b48195327/ and http://social.msdn.microsoft.com/Forums/en-US/vstest/thread/bfa792b0-b3fc-4a51-b49d-f7aaf1f2f4b8.
Nevertheless, since I have to implement code coverage into the continuous integration process somehow soon, and skipping that part is not an option, I am now asking here for any advice regarding this issue, and if there is any kind of solution to that problem!
Thanks for all advice!
Fakes is not supported by MsTest: http://msdn.microsoft.com/en-us/library/ms253138.aspx.
Here's how you can run the Visual Studio Testrunner from Team City (which supports Fakes): http://blog.degree.no/2012/09/unit-testing-visual-studio-2012-fakes-in-team-city/
You can also use the Visual Studio Testrunner if you use TFS.

TFS2010 build with unit test

I am trying to convert a build system setup with TeamCity and Nant scripts to use TFS2010 (We bought the license and might just as well make use of it) After some work I get the web project to build and deploy to the web-server. We have a domain, API, test and web project in our solution.
How do I configure TFS to run the unit tests that we have written so far? I did configure the build to look for ***.UnitTest.dll in(VS2010) Edit build definition>Process>Automated Tests
Now the build fails with a message that says:"Could not load file or assembly 'nunit.framework, Version=2.5.3.9345" Am I correct when I say that TFS is trying to run NUnit on the build server? I did install NUnit-2.5.3.9345 on that TFS2010 build server and still nothing?
Thank you
Jack
The build facility in TFS uses MSTest as test runner, with which it's tightly integrated.
If you want to run your unit tests with NUnit as part of your build, take a look at the NUnit for Team Build project on CodePlex.
The project started out for TFS 2008, however support for TFS 2010 has been added in version 2.0. Note that this feature is still in early stages of development, so your mileage may vary.
I'm late to the game, because I've had to deal with this issue recently. I found this article helpful for me in this. It didn't work right off the bat, but I found if I added it into my buildscript via the controls in a similar manner/pattern, it would work.
My only problem now has been getting it to actually error (right now it warns) even when flagging them to cause the build to error
Link: http://blog.gfader.com/2011/06/running-nunit-tests-in-tfs-2010.html

When do we use msbuild file?

I am working on a web application in VS 2008. To compile the applicaiton I go to Build in Visual Studio and click on Build Solution and when i have to deploy the site I click on Publish and it publishes the site to a directory.
Now my question is when do we use this msbuild file? what exactly this file does for Us?
Thanks.
You use a Build file when you have to do a series of operations that you want to do before or after compiling. This is used in most of the big projects where there will be other things (examples for other things are given below) that needs to be done and through MS build they will automated.
Examples of things that can be done with build :
Running Unit tests
Functional testing
Static Code analysis and reports
Packaging as an installer