I am very new to Unit-Testing.
I have a solution with C# project. I added to it a new NUnit project and added some tests.
I can run my tests using Test Explorer of Visual Studio, and even using Command-Line in the developing platform:
D:\Project\GuiTests\bin\Debug\netcoreapp2.1>dotnet test GuiTests.dll
I want to do a similar thing, but on a testing platform, which does not have Visual Studio and the source code.
I want to copy there only the tests folder (i.e. D:\Project\GuiTests\bin\Debug\netcoreapp2.1) and run the tests using Command-Line.
Is it possible? How can I do that?
Currently, I tried it out and got:
===
I tried using nunit-console and got this error:
Could not load file or assembly 'nunit.framework, Version=3.10.1.0,
Culture=neutral, PublicKeyToken=2638cd05610744eb' or one of its
dependencies.
Googling it, seems nunit-console does not support .Net Core.
So I think I should go on with the dotnet test
You can read the documentation of NUnit Console Command Line
The console interface runner is invoked by a command in the form
NUNIT3-CONSOLE [inputfiles] [options]
where inputfiles is one or more assemblies or test projects of a type that NUnit can process and
options is zero or more options. Input files and options may be mixed in any order.
Related
I'm trying to set up a Jenkins server for my C# Project. The Server currently runs on my localhost as I'm testing it out.
So far, I've managed to restore NuGet packages, and build the project, using 2 steps in the Build config.
Now, I'm trying to have it execute our unit tests. The tests are made using Microsoft's own test framework.
I initially tried to use the plugin to run the tests, and also set it up using a windows bat file, both result in the same problem.
The dll assembly cannot be found.
My bat command looks like this:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe" /resultsfile:"%WORKSPACE%\Results.trx" /testcontainer:"%WORKSPACE%\msTests\bin\Release\netcoreapp2.0\msTest.dll" /nologo, the result being: Test file not found.
I assume this is because Jenkins removes the build assemblies on success? How can I disable that? Or something else I'm doing wrong?
If you are using dotnet core you should be using the dotnet test command.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test?tabs=netcore21
I'm using VisualStudio 2015. I have installed the NUnit3 (3.5), NUnit3TestAdapter (3.6 also installed the VS extention), SpecFlow (2.1.0) and corresponding Selenium drivers NuGet packages.
I have one solution with two projects in them. One projects builds perfectly and discovers the feature test in them. But my other project build perfectly and the test aren't discovered. If I go to the test output I get the following FileNotFound / Converting error:
------ Discover test started ------
NUnit Adapter 3.6.1.0: Test discovery starting
Exception System.IO.FileNotFoundException, Exception converting Calculations.Calculations.Feature.SendANewQuote.SendANewQuote("18-1980","150","Yearly","1337","RiskProfile","email#email.com",System.String[])
Could not find file 'PathToCalculations\bin\Config\Calculations.pdb'.
It is the same for all my other tests in that project. I don't have that problem with my other project but all the references and packages are the same.
How can I fix this error so that the NUnit Test Adapter can do it's magic?
There was recently a change with either the adapter, or VS, that means a pdb file must be generated when using the adapter. There is an open issue to investigate this here: https://github.com/nunit/nunit3-vs-adapter/issues/276
It sounds like you might not be generating a pdb for the 'Calculations' project. You can turn it on by going in to the project settings > Build > Advanced, and selecting full or pdb-only from the Debug Info dropdown.
I'm using Selenium with C# to create my automated tests. Now i have to use some sort of reporting tools to save the test cases whether they passed,failed...etc.
I've seen a lot of tools like Allure, and Jenkins. But they require an XML file. and i can't find it when i run my tests using Visual 2013. Why is that ?
how to obtain these XML files in details if i'm missing something ?
Is there any way i could achieve this with minimum effort ?
EDIT:
How can i run my tests using Nunit console runner ? where can i find it? i downloaded the .zip for nunit but i couldn't find the runner?
The NUnit Visual Studio Adapter does not currently produce XML results, although there is an issue on GitHub to add the ability. Your best bet is to run your tests using the NUnit Console runner when you want to create reports. It always produces an XML result file.
You can install the NUnit Console by adding the NUnit.Console NuGet package to your test project. The console will be in a directory like packages\NUnit.ConsoleRunner.3.4.0\tools in your solution root.
Another option is to install the MSI for the console runner. It will then be under C:\Program Files (x86)\NUnit.org\nunit-console
For creating reports, ReportUnit creates excellent HTML reports from your test results.
To run the tests, I would recommend setting up a simple command line build that builds your solution, runs the tests and then produces the report. For day to day development, just running your tests in Visual Studio or on the command line will likely be enough. Most developers find the Visual Studio Test Explorer Window to be a poor UI, but usable for seeing passed and failed tests and running/debugging them.
If you want to setup a command line build, one good tool is Cake Build. It will take a bit of time to setup, but it is an excellent way to run your build tasks as your project gets larger.
NUnit testing can be run with the nunit-console.exe application which is installed with nunit under {Project_root}/lib/nunit/nunit-console.exe. It downloads with NuGet when NUnit installs.
It can be passed a list of testing binaries, or testing project files, or an nunit project (listing multiple if needed).
{PathToProject}\lib\nunit\nunit-console.exe {PathToTestDll}\Project1.Tests.dll {PathToTestDll}\Project2.Tests.dll /xml=nunit-result.xml
or create an NUnit Project with the NUnit Project Editor if you want to group all your test projects into a single config file.
{PathToProject}\lib\nunit\nunit-console.exe {PathToNUnitProject}\Project.Tests.nunit /xml=nunit-result.xml
Allure doesn't require xml. At lease now :)
https://github.com/unickq/allure-nunit
You just use [AllureNUnit] attribure
I have some problem to use both the NUnit Visual Studio Test Adapter and a framework extension class I've created. In particular my solution has 2 projects: the first one is a class library that contains some methods I must test and the second one is the test assembly. This assembly includes the extension class (I don't add the related dll to the addin folder inside the NUnit program directory because that extension class has been created exclusively for this assembly) that I have created to get and use the assertion failure messages.
Question:
I would like to have a BIN folder (next to my solution folder) where place all the DLLs I need, and use this BIN folder to run my tests from Visual Studio (that is why I need the NUnit Visual Studio Test Adapter) and through the NUnit-x86.exe program (I mean through the NUnit GUI).
At the moment I can run correctly all my test only by running them from Visual Studio... through the NUnit GUI the extension class does not work (I mean that my extension is invisible, I don't mean that there is something that gets error).
How do I have to set my project?
Extra info:
I'm using NUnit 2.6.4 and VS 2013 Professional on a 64bit machine.
To use the test adapter I followed this guide
OK, now I know what is the problem.
On a 64bit machine if you want to use the NUnit GUI you must use the nunit-x86.exe program; if you want to use your extension when you run the NUnit GUI then it needs 3 specific DLLs (nunit.core.dll, nunit.core.interfaces.dll, nunit.util.dll) located in the lib folder in C:\Program Files(x86)\NUnit2.6.4\.... These 3 DLLs are not the same DLLs that you need to run your test program in Visual Studio. Visual Studio will use the DLLs obtained through the installation of the NUnit Test Adapter. The DLLs names are the same but a set is related to x86, the other one DLLs set to 64bit.
You can test it...
Use the DLLS located in C:\Program Files(x86)\NUnit2.6.4\bin\lib for Visual Studio... nothing related to your extension will happen. The same for NUnit GUI when you run the program using the DLLs that have been ''installed'' by the Test Adapter.
I am working on a C# WinForms application in VC# 2008 Express, writing unit tests with NUnit 2.5.5, and running them via the NUnit GUI program. Right now to run them I switch the output type to 'class library' and then switch back to 'windows application' after I'm done testing. I just have NUnit reading from the bin/Release directory, which is erased when I rebuild. I would like to be able to compile both the class library and executable with a single action so I can test via NUnit and still run as a windows application.
I was thinking to use the post-build events in VC# but have never used them (I'm new to NUnit as well), is there a way to accomplish this? Should I be doing this a different way? Any suggestions are appreciated!
It is a .NET goodie: the public classes in a EXE can be loaded from it just like a regular class library. There's no need to build it to a DLL.
Why not build your NUnit tests as a separate project within the solution? Simply add the main application as a dependency to the NUnit test project.
If you then set the NUnit module to build as a library, and the main application to build as an executable, you should achieve the desired effect.