How to call Nunit from Visual Studio in a batch file - visual-studio

I have set my Visual Studio to start Nunit as an external program to run all the tests written in a module.
Now what I am trying to do is to create a batch file which will call Myproj.exe. What I am expecting is that it will run Nunit as I have set it to run an external program and execute all my tests in nunit.exe, but when I run that batch file it starts running from Visual Studio instead of opening NUnit.
Can any one please give me a clear idea as how to accomplish it?
I am too much stuck.
Now I am trying to run the following commands in shell
nunit-x86.exe
Can you please tell how should I load my visualbasic project file (exe) here and then run all the tests from here
as unable to execute following command
nunit nunit.tests.vbproj /config:release

You can make NUnit start everytime you debug your "NUnit tests".
You can attach the debugger in Visual Studio Express doing it that way.
If you use a "full version" of VS do it that way:
Note that if you’re using the full and
not the express version of Visual
Studio 2005, you can do this by
opening up the project’s properties,
and in the Debug tab select Start
External Program: and navigate to the
NUnit executable, and set
YourCompanyname.YourProject.Test.dll as the
Command Line Arguments.
I got that ideas from this tutorial(Page 4/5) and love it.

You can also run NUnit after every successful build in Visual Studio with a Post-Build Event.
In VS2005, right-click on the project that has your tests and select Properties. Then on the Build Events tab, in the "Post-build event command line", put this* to use the console:
nunit-console /xml:$(ProjectName).xml $(TargetPath)
or this to use the GUI::
nunit $(TargetPath) /run
In "Run the post-build event:", leave the default: "On successful build"
If you use the GUI, know that your build will appear to be hung up until you close the GUI app.
*NOTE: The nunit console command line docs say "By default the nunit-console program is not added to your path."

you can just shell nunit.exe with the command line to your assembly to run tests in.

You can load nUnit.exe (nUnit-Console.exe for command line execution) using external tool features in Visual studio. Once you add the command via external tools feature (as explained in this blog), you can use it for any project to execute the tests. (Other is to add through project properties but that needs to be done for every project). Also in the arguments you can pass /include or /exclude to include or exclude categories of the tests.
The advantage of this method is you need not worry about giving path to DLL file and it works for any project you are on and gets executed with few clicks

Related

Visual Studio: How can I find corresponding CLI command for a GUI build operation?

I've been a linux/make guy and recently I'm learning to build UE5 engine from VS 2022. I need to figure out a CLI way to build it.
For example, I right click on one of the modules (not sure if it's the most proper name) and choose 'Build' then the build will start. I want to automate the procedure using CLI.
How can I find the corresponding CLI command for this manual operation?
I don't have access to the Unreal Engine source code and I don't know if Epic has done anything highly unconventional.
From your start menu launch the "Developer Command Prompt for VS2022". This is a shortcut file for launching the Windows command line with a batch file run to set up the PATH and other environment variables for the Visual Studio development tools.
Visual Studio project files (.csproj for C# and .vcxproj for C++ for example) are MSBuild files. (MSBuild was inspired by Ant, if that helps.)
Solution files (.sln) are a completely different format but MSBuild can build a solution file.
From the screenshot in the question I can see that the solution is UE5 which will be UE5.sln. I can also see that you want to build a C++ project. I'm guessing the project may be named BenchmarkTest (BenchmarkTest.vcxproj)?
MSBuild has a notion of targets. A target always has a name and it groups a set of tasks to be performed. (It's like a makefile rule in some respects but it's not the same.)
Solutions and projects created with Visual Studio support some standard targets. The 'Build', 'Rebuild', and 'Clean' menu items map directly to some of these targets.
Visual Studio solutions and projects support Configurations and Platforms. The standard Configurations are Debug and Release. The screenshot shows a non-standard configuration of Develop. The screenshot also shows a platform of Win64.
In the Developer Command Prompt, msbuild should be in the PATH. Try the following command:
msbuild --version
To build the solution with the default target (which is 'build') and the default configuration and platform:
msbuild UE5.sln
To run a 'clean':
msbuild UE5.sln -target:clean
The target switch can be shortened to -t.
The configuration and platform are passed as properties using the -property switch. The short form is -p. Multiple property switches can be provided and multiple properties, delimited by ';', can be provided in one property switch.
msbuild UE5.sln -t:rebuild -p:Configuration=Develop -p:Platform=Win64
or
msbuild UE5.sln -t:rebuild -p:Configuration=Develop;Platform=Win64
To build the BenchmarkTest project, specify the project file:
msbuild BenchmarkTest.vcxproj -t:build -p:Configuration=Develop;Platform=Win64

Explanation on specific differences between my click once publish when done via command line and from Visual Studio

I am trying to understand why is my WindowsForm app publish behaving differently, when done via command line and via Visual Studio's Publish.
The differences are:
In my command line publish, a copy of the .exe is placed in the top-directory publish folder, while it is not there, when published via VS
In my command line publish, the .application file is missing in the [Application Files] folder, while it is there when published via VS
A screen shot illustrating the exposed above:
Anyone has any idea why does this happen ? I have tried playing with the publish settings, but still without success.
Below is what my command line statement looks like (ran via Jenkins):
Explanation on specific differences between my click once publish when done via command line and from Visual Studio
That because some features are done by Visual-Studio and not by the MSBuild command line. So the click-once-deployment behaves differently when it's executed from the command-line.
When you publish via command line, only Project.exe and Setup.exe are copied to the deployment folder. You can switch the deployment folder by property PublishDir:
msbuild "ProjectName.csproj" /target:publish /p:Configuration=Release;PublishDir=D:\TestPublishFolder
When you publish from Visual Studio, Visual Studio will do some more features, including Application Files folder and .application file into deployment folder.
If you want to have the same publish result as Visual Studio when you publish via command line, you can custom target to achieve it.
See ApplicationFiles folder missing when ClickOnce publish with command line for more detailed info.
Hope this helps.

Chutzpah - is it possible to integrate chutzapah test running with visual studio build

Is it possible to integrate chutzapah test running with visual studio build?
What I mean here is - if any test fails the build fails.. .that way..
I think you have 2 ways of doing this:
install the Chutzpah test adapter on each build machine and get the running the tests in test explorer.
Then customize your msbuild scripts to run the tests.
Use the command line + custom msbuild task
It looks like Chutzpah has a command-line runner, so you can create a PowerShell script which gets called from your build server to run the tests. See the Chutzpah documentation for more information, but it should be chutzpah.console.exe under: Chutzpah.3.2.4\tools
Next if you want to integrate with Visual Studio build it means msbuild integration. Take a look at the exec task on how to run custom commands and react based on the results

How do I configure visual studio to run xUnit.net tests?

I have configured Visual Studio 2010 to debug xUnit.net tests by setting the Project Settings | Debug | Start External Program to run the xUnit.net console runner.
This works OK but only when providing the complete path to the test project dll via the Command Line Arguments eg: "c:\development\TestProject.dll"
I have tried using $(BinDir)$(TargetName)$(TargetExt) as parameters via the Command Line Arguements section but it does not work. Any suggests on how I can avoid the explicit/full path?
This is what I use in my .csproj file to run the xUnit GUI runner as the start action:
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(MSBuildProjectDirectory)\..\..\Packages\xunit.runners.1.9.1\tools\xunit.gui.clr4.exe</StartProgram>
<StartArguments>"$(MSBuildProjectDirectory)\$(OutPutPath)$(AssemblyName).dll"</StartArguments>
</PropertyGroup>
For this to work, all you have to do is install the xUnit.net Runners NuGet package:
PM> Install-Package xunit.runners
The only downside so far, is that it's version specific, so every time you update the NuGet package to latest, you should update this configuration to point to the correct runner.
This answer was given before James' and Brad's awesome work with xUnit.net Runners. See michielvoo's answer below.
To avoid the problem of explicitly giving the library name one can use cmd.exe with command line arguements: /C xunit.console.exe $(BinDir)$(TargetName)$(TargetExt)
Check Use Output Window
Use the Tools|Options|Keyboard configuration to assign a hot key.
A alternative route is use a VS plugin as testrunner. For instance ReSharper.
I simply type the full name of the assembly thats all.
Under command line arguments: SharedDataBridge.Tests.dll

VS2010 & SourceSafe 2005 - Logging into SourceSafe from the command line?

I have a custom application which brings together several resources and builds a Visual Studio project into an exe file I can then use to upgrade my company's website and database. This custom app uses System.Diagnostics.Process in a couple of places to access SourceSafe, I use the command SS ... -Y, to log into SourceSafe and process some events which works as I would expect. I'm not logged into the company's domain which is why I am manually logging into SourceSafe.
Now when I get to the part where I start building my VS2010 project, I'm using this command devenv /Build Release /Out ..\Log.txt /project <MyProject> it does not build my project, and the log file shows this error...
The following files were specified on the command line: <Path to my VS project> These files could not be found and will not be loaded.
The path to my project is correct and if I run it from a command window it loads the project, asks for my SourceSafe credentials and it builds. So my question is... Is there any way I can log into SourceSafe using the command line above, or by adding to the ProcessInfo parameters before I execute the command line?
You may check out the thread below and see if it helps:
http://social.msdn.microsoft.com/Forums/en/vssourcecontrol/thread/8d00f574-7d9d-4a0d-aa0a-4c7832df0379

Resources