running xunit from console
Asked Answered
M

4

10

I have, what is probably, a stupid question.

I'm trying to run an xunit dll from the command prompt.

I find that I need the following dlls to be in the folder that the command prompt is in.

xUnit.Console.exe,xunit.console.exe.config,xunit.dll,xunit.runner.utility.dll

which is fine I guess but then I can't get it to run my tests.

At first I tried using a relative path to my test dll and it was not having that.

so then I put the test dll in a folder with the above dlls and ran it. Now the result is it says I"m missing a dependency for my test dll.

So then I put the xunit files in the bin folder with my test project dlls and it tells me that it can't even find the test dll that it's sitting next to.

This all seems very difficult what i want is to do this given the following structure

--src

----tools

------xUnit

--------all my xunit dlls

----projects

------MyTestProject

-------bin

---------MyTestProject.dll

lets say

c:\Src\Tools\xUnit>xunit.console ..\\..\Projects\MyTestProject\bin\MyTestProject.dll
Mayotte answered 9/1, 2014 at 18:26 Comment(0)
D
3

Two solutions: 1) Add C:\src\Tools\xUnit to your PATH environment variable and run the xunit console app from a command prompt where the current directory is C:\src\projects\MyTestProject\bin.

2) As per the first suggestion but rather then putting it in your PATH environment variable, specify the whole path (relative or absolute) to the xunit.console.exe on the command line as the executable to run.

Daudet answered 11/5, 2014 at 18:23 Comment(1)
Could the downvoter explain why the answer didn't work for them?Daudet
M
1
  • Run the Command Prompt

  • Run the next command and replace 'path_to_xunit_console' with the path of xunit console

    set PATH=%PATH%;path_to_xunit_console_exe
    
  • move to location of your unit test binary project:

    cd  my_test_binary_folder   
    
  • Run the next command and save the logs to xml file:

    xunit.console your_test_dll_file   -xml testlog.xml
    

To know the different options run:

   xunit.console -?

You can automate these steps by creating a batch file, test.cmd, in the binary test folder:

 set PATH=%PATH%;path_to_xunit_console_exe
 xunit.console your_test_dll_file   -xml testlog.xml
Murmur answered 11/9, 2018 at 17:36 Comment(0)
G
1

Way to find xUnitConsole.exe Search the package in

%userprofile%\.nuget\packages

.nuget\packages\xunit.runner.console->Your Version installed->Tools->xUnitConsole.exe

Guenna answered 8/9, 2020 at 7:18 Comment(0)
M
0

I wound up building an xUnit console test runner in C# to cycle through and run all the xUnit test assemblies in a given folder.

The structure I wound up with was the xUnit test runner, named RunXUnitTests, in a folder one level above the test assemblies, with the executable and the assorted support dlls it needed. For example NLog logging support and some email support dlls for sending out a results email were in this RunXUnitTests folder.

Immediately under the RunXUnitTests test runner folder, there is a "TestAssemblies" folder, and all the xUnit test assembly dlls went in that folder, along with whatever supporting dlls were required by the tests themselves. Also, all the xunit.console.exe runtime files were in the TestAssemblies folder. It was least confusing to have all the tests and their dependencies in the same TestAssemblies folder, separate from the test runner.

To run the tests, from the console, the C# test runner app would submit command lines to the System.Diagnostics process execution API, with the xunit.console.exe command as the process to run, and the test assembly and the (xml) results file as command line parameters.

A typical command line, for Operational Readiness Tests (ORT), that was formatted by the test runner, and submitted to a process.Start() method call (where the process object is of type System.Diagnostics.Process), is as below:

"C:\RunXUnitTests\TestAssemblies\xunit.console.exe" "C:\RunXUnitTests\TestAssemblies\SharePointBasicFeaturesORT.dll"  -xml "C:\Users\Public\Documents\TestResults\SharePointBasicFeaturesORT.xml"

After the tests ran, the test runner program had some routines to spin through the XML results files, extract the results, format a results summary email (in HTML), and send the email to a distribution list.

I should mention that all this is packaged up into installable MSI files that can be deployed to Windows 7/10 PCs or VMs for test runs. We are using it to run SpecFlow+xUnit "Operational Readiness Tests" on our web applications on a scheduled daily basis. We used the Wix# ("WixSharp") installer to build our installers in C# and then have the Wix Installation Toolset build standard MSI installer files. See https://github.com/oleg-shilo/wixsharp for more info and the source and binaries. It works very well once you get the hang of it.

Yes, it's a fair amount of work to do this way. I wouldn't recommend it if your organization already has other DevOps type tools that can do this work, e.g., Jenkins, TeamCity, Bamboo, Azure for DevOps etc. My organization is still "in process" on bringing in such tools, and it was more doable in the near term to evolve the test runner than to get organizational decisions, financial commitment, and installation and configuration support for DevOps/CI tooling.

If you don't have ready access to DevOps/CI tools, this type of approach uses freely available open source tools (aside from paid versions of MS Visual Studio; I don't know what the community editions do and don't work for) and is workable as a bridge to a more sophisticated environment.

Merovingian answered 11/5, 2019 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.