I spent far too much time trying to run a basic NUnit test on a Microsoft Store app. I installed NUnit v3.0.1 and NUnit3TestAdapter on VS2015 Pro but I get the following which confirms that the test is not discovered:
------ Discover test started ------
NUnit Adapter 3.0.8.0 discovering tests is started
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in <project exe file>
The NUnit 3.0 driver does not support the portable version of NUnit. Use a platform specific runner.
NUnit Adapter 3.0.8.0 discovering test is finished
========== Discover test finished: 0 found (0:00:01.0639991) ==========
The NUnit.Engine.NUnitEngineException error referred to is not helpful because there is no way of exploring where the exception is in my program. The test is a single method with one Assert statement just to test if the setup works so there is nothing complicated. I also don't understand what a "platform specific runner" is. I installed both NUnit and NUnit3TestAdapter thru NuGet Package Manager and I presume installations for relevant platform and version are carried out.
I even tried out installing "NUnit Templates for Visual Studio". This allowed me to create an NUnit project, and interestingly the test within NUnit project is discovered and run. But the downside is that I cannot reference my UWP app project from the working NUnit project, I think because the NUnit project only supports .Net frameworks (up to 4.6.1) not Windows 10 platforms.
I have used NUnit before for non UWP applications without much trouble. Am I missing something or NUnit as yet doesn't support UWP apps?
At the moment you can only test DNX projects with XUnit.
Here is a nice starting point for that.
From the official Asp.Net 5 documentation (which uses the same infrastructure as UWP):
For example, to work with the xUnit test framework, you would
configure the dependencies as follows: [example project.json I dont
want to copy]
As other test frameworks release support for DNX, we
will link to them here.
Since there are no other frameworks linked in the documentation, I assume that there are none that support DNX projects at the moment.
Since this question was originally posted NUnit has developed it's support for testing UWP/Xamarin apps. Check out the nunit.xamarin runners.
Essentially, your tests should be created in either a portable library, or a shared project. This can then be referenced by a UWP project runner, which can be run on the emulator.
If you take the shared project approach, you can also reference this through an .NET 4.5 project, which will allow your tests to integrate with the NUnit VS adapter, and show up in VS. Portable libraries can not yet be run with this runner, however that's in the pipeline.
Related
I recently created a unit test project(.net framework) in my project(.net framework 4.8).
I run my tests with visual studio enter image description here.
now wanna add a stage to my ci/cd on gitlab to run my tests.
I know how to do that in .net (dotnet test) but I don't know how to run my tests for .net framework with command line
I'll be happy to know your solutions.
Tnx
The VSTest.Console.exe tool can be used to run unit tests. This is equivalent to using the Visual Studio Test Explorer window.
VSTest.Console.exe is installed with Visual Studio. It is also available in the Microsoft.TestPlatform NuGet package.
(As a note for the benefit of users of Azure DevOps, Azure DevOps pipelines has a Visual Studio Test Platform Installer task that will install the test runner. The Azure DevOps task uses the NuGet package.)
For .net framework you should get familiar with MSBuild. If you are using MSTest you also need to know VSTestConsole. Not too hard!
Here is a minimal GitLab CI config for a .Net framework solution.
Also check here for more detials.
I wanted to setup a quick test project to test a few things in my solution. The solution has a few projects in it some class libraries, windows forms projects, etc. I just wanted to test something and now this is turning into a major pain and taking over an hour, and I don't understand why.
I add a new test project to the solution (only seems to have .Xunit or MSTest .Net core, does that matter?) and then add the appropriate project references. Running the test project from scratch works fine it's only when I set it up to run with my other projects (in the same solution) references does it get confused referencing my projects.
This issue seems to be more related to Visual Studio and test projects than MSTest or Xunit, I tried both test frameworks and get the same type of issue it can't find tests.
It's basically the same in both frameworks just can't find tests even though annotations are correct:
[12/1/21 6:37:52 PM Warning] No test is available in C:\Users\main\Tests\bin\x86\Debug\netcoreapp2.1\CadWrapperTests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[12/1/21 6:37:52 PM Informational] ========== Discover test finished: 0 found (0:00:03.2242021) ==========
[12/1/21 6:38:22 PM Informational] Executing test method 'Tests.CheckDrawingIsClosed'
[12/1/21 6:38:23 PM Error] System.InvalidOperationException: The following TestContainer was not found 'C:\Users\main\Tests\bin\Debug\netcoreapp2.1\CadWrapperTests.dll'
The projects are all using .NetFramework and x86 architecture, but the test project only lets me choose .Net Core and when I add new .NetCore test projects are the only options, is that the issue?
It won't find tests and the errors aren't useful but it shouldn't be this difficult to add a test project and write some tests..
I have build the unit test DDL on my machine and run on the another place without installing visual studio.
To do this, I install the NUnit command line and call the my unit test DLL, and it does not work.
In my C# code I only add the [TestMethod] attribute on my test method.
The below image shows how I call the NUnit on the command line:
Is there an issue in here, or is there any other way to do this?
Note: I use the Selenium library in my project.
The NUnit console runner is made to run NUnit tests, that is, tests that use the NUnit framework. Since you are using the [TestMethod] attribute, you are probably using Microsoft's test framework.
NUnit used to be delivered (version 2) as a single package, but with version 3 it is divided into several different packages. You will have to download and reference the NUnit framework and change your tests to use its attributes and assertions.
I am working on selenium web driver project. I was able to built tests in Test Explorer and execute.
At once I am getting following errors when rebuilding the solution.
Unit Adapter 3.2.0.0: Test discovery starting
NUnit VS Adapter 2.0.0.0 discovering tests is started
NUnit Adapter 3.2.0.0: Test discovery starting
NUnit VS Adapter 2.0.0.0 discovering tests is started
Attempt to load assembly with unsupported test framework in C:\..\CustomerTest.exe
NUnit VS Adapter 2.0.0.0 discovering test is finished
Attempt to load assembly with unsupported test framework in C:\..\LoginTest.exe
NUnit VS Adapter 2.0.0.0 discovering test is finished
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in C:\..\CustomerTest.exe
Cannot run tests in process - a 32 bit process is required.
NUnit Adapter 3.2.0.0: Test discovery complete
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in C:\..\LoginTest.exe
Cannot run tests in process - a 32 bit process is required.
NUnit Adapter 3.2.0.0: Test discovery complete
========== Discover test finished: 0 found (0:00:02.5558095) ==========
I have changed the default processor architecture in to X64, but issue not resolved.
Please help me to resolve this issue.
Thank you.
I had this problem just today for some odd reason, because I didnt change anything in the meantime and it worked before.
Fixed it by: Project-> [YourProjectName].properties -> Build -> Platform target: "Any CPU" -> Untick "Prefer 32-Bit"
It seems to be the same problem like here: Visual Studio FsUnit test setup - Exception NUnit.Engine.NUnitEngineException So installing Adapter Version 3.0.10 should solve your problem. At least it did for me.
You can follow the issue on github.
I faced the same problem with NUnit 3 Test Adapter (version 3.2.0). I uninstalled it and tried NUnit Test Adapter Version 2.0.0.0. That solved the problem for me.
I used the VS > Tools > Extensions and Updates to install/uninstall the adapter.
My VS project is set to build for Platform x86 and I was using VS Ultimate 2013 Update 5.
I had the same problem with my .NET Core 2.0 project with NUnit 3.9 in Visual Studio 2017 and was stuck with this for quite some time. None of the solutions suggested in other related questions worked.
Then I figured out from this link that a class library with target .NET Standard does not work. The test project has to target .NET Core. Also, Microsoft.NET.Test.Sdk NuGet is required.
So, the steps are
Make sure that the test project targets .NET Core
Install latest NUnit NuGet (I used 3.9)
Install corresponding NUnitAdapter NuGet (I used NUnit3Adapter)
Install Microsoft.NET.Test.Sdk NuGet
Re-build and your tests will appear in Test Explorer in Visual Studio.
I am trying to get a file working on OS X which requires the use of the [TestClass()] and [TestMethod()] attributes. Im new to c# (Ive used java for a few years now) so Im not sure, but I think these attributes are part of Microsoft.VisualStudio. Since I'm on OS X I an using mono to compile and run C# files. How, if possible, can I get the same functionality as the Microsoft.VisualStudio.TestTools.UnitTesting namespace?
Xamarin Studio / Monodevelop has a unit testing add-in which allows running NUnit tests within the IDE. The add-in should be installed by default. If not, you can install it through Tools > Add-ins.
When you build a class that has [TestFixture] attribute and it has a method with [Test] attribute - you can run it from View > Pads > Unit Tests or green icon at signature line. In this screenshot, lines 12 and 26:
Additionally, there should be a project template which already has NUnit package pre-installed and a test class ready:
[TestClass()] and [TestMethod()] are part of MSTest framework and are not available in Mono.
Have you looked at using a mono build of Nunit you can also use "using mapping" to convert you ms test attributes to nunit here is an example http://www.martinwilley.com/net/code/nunitmstest.html
If using mono isn't a requirement, you could also look at using .NET Core it's still in development but it's the full .net stack by Microsoft for OSX and Linux