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
Related
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.
I have a solution containing a few projects, three of which startup when hitting the Start button, which are integral to the operation of the program. I have some tests, which have been found by Visual Studio and are inside the Test Explorer panel.
The question is: When I hit the Run All button inside the Test Explorer panel, how can I tell Visual Studio to startup the same projects as when I hit the Start button?
The only way I can see it being done is by using a *.testsettingsfile to use a Setup script that will run the projects, but it just feels like a dirty way of doing it.
Any ideas?
Open two visual studio apps, one for running your three projects and the other for running the tests. But I think only functional/integration tests need to test the executions which are running currently.
The way I have accomplished this in the past for system tests that need the main executable running is to leverage the Assembly Initialize in the test project and have it start the required exe.
We have a build setup that puts all of our debug output into a common location, so we can find the appropriate exe because it is in the same path as the test assembly.
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext context)
{
// Launch the exe here.
}
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 have a console application built in visual studio 2010.
When I actually build the project I am getting .exe file under \bin\Debug\MyProj.exe.
When I Paste and run this .exe from other location it is expecting other files too.
Any thoughts how can I make this as Stand alone exe file.
There should be other DLL's in the Debug library. You need those to run your exe.
If there are no DLL's there, make sure you set the 'Copy local' property of the required references to True, and build again.
If you want to make a standalone program, you should create a new Setup project in your solution. Include the Primary Output from your application project, and the setup should include the required DLL's automatically. Once you build the setup project, you can install your application as a standalone software.
You usually distribute application with bunch of DLLs, that's nothing bad.
But if you really want to make it a single exe, you can look here - same question is answered Embed .net dll in c# .exe . (Valid if your DLLs are also .Net assemblies)
Edit: If you need to easily distribute app to not-very-computer-friendly users, consider also trying ClickOnce. It's roughly something like Java Web start - only disadvantage is that you can't get "Windows Logo" certificate from Microsoft for projects distributed that way.
I don't have Visual Studio 2010 to experiment with, but in Visual Studio 2019 this worked:
Project Properties->Configuration Properties->Advanced->Use of MFC->Use MFC in a Static Library
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.