Runtime folder structure when running xUnit.net tests - c#

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.

Related

Why do I have files from "C:\Program Files\IIS\Microsoft Web Deplay V3" in my c# project's bin/Debug directory?

I have a visual studio 2019 solution with a few projects that consist of mostly c# class libraries. This solution is never 'deployed' and is always run locally by anyone who uses it. Part of what we do for one of our test projects to work is put certain dll's we use into our bin/Debug folder. One of these is Newtonsoft.Json.dll for example. We have a specific version of that dll that we're required to use.
This is something that is usually done once, the first time we run a test in that project. This all works fine. However, whenever there is a code change and the project builds, for whatever reason all the files that are in "C:\Program Files\IIS\Microsoft Web Deploy V3" are copied into our projects bin/Debug directory and overwriting any of the same files already there (Newtonsoft.Json.dll being one of them), and it's a different version which then breaks our projects dependency on that version of the dll. It's worth nothing there are also a bunch of random other files/folders in that Web Deploy directory that get copied over that our project does not need to be there.
I've checked all build events, and searched the entire solution to see if we reference that directory at all which we don't. I've tried googling similar issues, but almost all of what I can find is related to how to use Microsoft Web Deploy (which as far as I can tell we're not, and intentionally as I mentioned we don't deploy any of this code).
If anyone has any insight on this, it would be greatly appreciated!
Thanks,
Andy

NUnit extension does not work running tests through the NUnit GUI

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.

running a c# test project through an exe file

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

Assembly Not Found on deployment of C# project

So I made a C# project in visual studio with 3 class library projects. Everything works fine when debugging but When I try to deploy. Database and Program installs just fine but when I try to open the Application, I get an Assembly or File not Found Exception. The DLL he can't find is a class library in my project.
On the File System Editor, VS automatically detected the dependencies and included the 3 dll files in to application directory. I tried excluding these dll's and just adding the class library projects's primary output's (Same dll) but still the same error.
I used a Custom Installer class for creating my database on installation. But I don't think that is relevant.
If you have verified that your 3 assemblies are indeed deployed to your destination folder,
it could very well be an another dependency that you have not included in your setup project.
Please double check that you indeed have the right number of assemblies included.
You can also right click the setup project and refresh dependencies.
Have you checked that dependencies in the setup project aren't excluded (by mistake)?
Furthermore, it may also be a .NET profile issue. Do you depend on assemblies that are only available in the full .NET profile, and your destination only has the client profile installed?
In worst case, run the SysInternals process monitor and that way figure out which assembly is missing.
you need to include all dll's that are not part of the .net framework with your deployable. Your custom installer will copy these files to the location of the executable on install.
i usually create a folder called /deploy and copy all my needed dlls in there. I also change my projects settings to output to the /deploy-directory (instead of bin/). after you build, this directory will contain all dll's and other resources needed to run the application.

Running nUnit from code generated by msBuild out of Jenkins

My company is moving to continuous integration using Jenkins.
We keep our code in Subversion.
We code in C# (well I do, the others use php).
I've hit a snag, I can't get nUnit to work when I compile the project .
My project is a very simple one with just a single class and a few nUnit tests.
Works fine in Visual Studio. It builds and I can run the NUnit console to test the code.
I can use Jenkins to extract the project from Subversion
I can then build the code with msBuild.
However, when I try to run NUnit from the the NUnit console I get told that nunit.framework.dll is missing.
nunit.framework.dll is in C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework
I think it is looking for the nunit.framework.dll that is referenced by the project. Which is required to add NUnit tests to the project.
I note that when building from Visual Studio nunit.framework.dll is copied to the bin folder.
I note that no contents of bin are stored in Subversion.
I had to put a copy of nunit.framework.dll into
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client
so that msBuild could find it.
How do I get nunit.framework.dll into the output bin folder when using Jenkins and msBuild?
I've looked through a number of posts but non address this point.
Any thoughts would be welcome.
Thanks,
Richard
In your Test project where you reference the Nunit.Framework.dll, right click on that and select properties ( or press Alt + Enter ) and make Copy Local to be True
Subversion does not store output files ( i.e. dlls) by default. I rebuilt the project and added nunit.framework.dll to subversion. That way it gets popped out by Jenkins and can subsequently be referenced.

Categories

Resources