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.
Related
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.
I'm working on a C# web app running on .net 4.6.1 that assumes that certain dlls are in the same folder as the executing assembly and tries to import some types from those dlls using MEF. That works fine when the app is running and all the required dlls are in the bin folder, but I have problems when running xUnit tests that eventually get to run the code that makes the assumption mentioned above. I'm running the tests using Visual Studio 2017.
The problem I have is that when I run an xUnit test it creates a temp folder which contains a subfolder for each reference I have in my unit test project. In every subfolder there is the .dll and the .pdb file of a single reference along with an __AssemblyInfo__.ini file. Obviously, the test crashes with a FileNotFoundException because the code that wants to import some types using MEF cannot find the dlls in the same folder as the executing assembly location.
Is there a way to tell xUnit to put all the references of the unit test project in a single folder (like the bin folder?) and run the tests using that folder? Or is this maybe a setting in Visual Studio 2017?
You can simply disable shadowCopy, so that all execution uses your output folder.
To learn how to configure xUnit.net via JSON, use a search engine.
My problem is very similar to NUnit Unit tests not showing in Test Explorer with Test Adapter installed, in that I couldn't get the NUnit tests to appear in the Test Explorer (despite multiple rebuilds, setting the Test architecture to x64, etc). I rebuilt and rebuilt, and despite having NUnit 3 and the NUnit 3 Test Runner installed into my Solution (via Tools -> NuGet Package Manager -> Manage NuGet Packages For Solution...) I couldn't get the tests to appear.
On the advice of another response to the above question, I installed the NUnit 3 Test Runner as an Extension (which modified all of Visual Studio, not just my project).
After the extension is installed (and I do Yet Another Rebuild :) ) all my tests are listed in the Test Explorer.
Question: Why do are the tests shown in the Test Explorer for the Visual Studio-wide NUnit 3 Test Runner Extension, but NOT in the Solution-specific NUnit 3 Test Runner NuGet package?
What's even weirder is that the exact same project, with the per-Solution NuGet packages for NUnit, work just fine on my personal computer (WITHOUT the NUnit Extensions installed), using Visual Studio 2017 Community edition. It's only when I .ZIP the project and email it to another computer (which runs Visual Studio 2017 Enterprise) where I have this problem.
I'd prefer to install NUnit into the solution so that I can hand out copies to my students and have the project be completely self-contained.
Does anyone have any advice on how to further dig into the problem with the per-Solution NuGet package? I'm kinda stymied since the only obvious thing to try is "rebuild it again and see if that helps" :), so any thoughts on stuff to try / strategies to use would be great.
At this point it looks like the Virtual Machine that I'm running the tests in thinks that the project is being run from a network drive. .Net has different rules for running code remotely and by default doesn't want to execute remote code (which seems reasonable :) ).
It's worth pointing out that NUnit should (and does!) work just fine in a VM where the project is saved onto a virtual disk - it's just the 'network drive'/file share that's causing the problem.
I have a bunch of c# tests that I want to run through a powershell script. I am currently doing this by creating a windows application project, writing the tests as a part of a general class and compiling it into .exe and running the exe but its not the right way to go.
How can I, say, create a class (that can come out as .exe) that can run all tests in a given project or some other way that I can easily run all tests through a powershell script, which is used for application deployment
Try to use MSTest.exe. There are lots of parameters
Example from the link above.
mstest /testcontainer:Errors.dll /detail:testtype
or (VS90COMNTOOLS change to your version)
"%VS90COMNTOOLS%\..\IDE\MSTest.exe"/testcontainer:Errors.dll /detail:testtype
or (change 'Microsoft Visual Studio 11.0' to your VS folder)
"%PROGRAMFILES%\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe" /testcontainer:Errors.dll /resultsfile:out
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.