I've created ASP.NET we app project and then I've created a test class - this class is part of the .NET core.
I need to run the test by the console but I can't use .net core. because the app has to be compiled, etc. with MSBuild, so I have been doing some research about how to run xUnit test inside MSBuild task.
I found this https://xunit.github.io/docs/running-tests-in-msbuild#options.
So I installed xunit.runner.msbuild.net452.dll but I cannot run the test.
error : System.InvalidOperationException: Unknown test framework: could not find xunit.dll (v1) or xunit.execution.*.dll .....
Is .NET framework is compatible with xUnit?
Related
I have a simple selenium test on .net core 3.1 with selenium.webdriver.
I build it on the build pipelines with yaml that does Restore > publish > publish artifact. The Dlls look fine.
I put this into a release pipeline and I keep getting:
My pipeline tasks are a Pipeline Platform installer running the Latest and a VSTest task that runs the "Installed by tooler".
My Agent is Azure pipelines with windows-2019. Not sure what I am missing here. I cant run this simple test. Thanks
If you using VStest task to run dotnet-core-3.1 tests. You need to specify the framework option to .NETCoreApp,Version=v3.1 in the Other console options field: See below:
- task: VSTest#2
displayName: 'VsTest - testAssemblies'
inputs:
testAssemblyVer2: |
**\*Test*.dll
!**\*TestAdapter.dll
!**\obj\**
codeCoverageEnabled: true
otherConsoleOptions: '/framework:".NETCoreApp,Version=v3.1"'
You can also use dotnet test task in the release pipeline to run the tests on .net core 3.1.
I was trying to create some unit tests in xUnit using .NET Core and using Moq. I created the project then added Moq using NuGet. I see in the dependencies of the xUnit project under NuGet that Moq (4.7.99) is there but I am not able to use it in code.
When I add:
using Moq;
I get an error saying Moq could not be found. What am I missing?
I've written tests using Selenium in NUnit Framework using C# language. I want to associate these tests as part of builds in the TFS. So whenever new build is generated. These tests would be able to run as part of builds and generate/email reports as well.
Recommend you to use the new build system vNext build. vNext builds are JSON based, and you can plugin tasks built in msbuild, powershell and varied other scripting languages.
About how to integrate NUnit Tests in TFS builds, this blog describes clearly how to do this: Running NUnit Tests in a TFS 2015 Build vNext
Simply summarized as follows:
Add Nuget Package for NUnit Test Adapter
Specify path of custom Test Adapter inside build definition
Copying adapters inside Visual Studio TestWindows folder
Specify Path to Custom Test Adapter with nunit packages
Some other tutorial for you reference:
xUnit or NUnit with Visual Studio Online Build
Running nUnit and Jasmine.JS unit tests in TFS/VSO vNext build
I am trying to add reference to ASP.NET Core Web Application from Class Library project (.NET Core) which will be my Unit Tests project.
I am getting error with default empty projects(File -> New Project):
I have tried to downgrade Tests project to 1.4 with no success.
netcoreapp is for applications(web, console and test), netstandard is for class library projects.
So, changing netstandard1.5 to netcoreapp1.0 in test project's project.json will solve your problem.
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