Using The MbUnit Console Runner
MbUnit proffers two applications for running tests against your code. The GUI runner discussed on this page and the command-line-based application discussed here. You'll find them both in the MbUnit installation directory; c:\program files\mbunit by default. If you intend to use the console runner a lot, it might not be a bad idea to add its location to your PATH enivronment variable.
At any point while using the console runner you can bring up a summary of this page by typing any of the following alternatives
MbUnit.Cons.exe
MbUnit.Cons.exe /?
MbUnit.Cons.exe /help
Full Syntax
MbUnit.Cons.exe {AssemblyToTest[...]|ProjectFile} [[/ap: assemblypath ] [/rt: reportType [/rf: reportpath ] [/rnf: reportname ] [/tr: transformpath ] [/sr ]] [/fc: categoryName[,...]] ] [/ec: categoryName[,...] ] [/fa: authorName ] [/ft:className] [/fn: namespace ] [/v: {+|-} ] [/sc: {+|-} ]]
Parameters
- AssemblyToTest[....] : A list of one or more assembly dll files containing tests you want Mbunit to run. Use the full path to the dll if you aren't calling MbUnit.Cons while in the directory containing the test dll.
- ProjectFile : The name (and location) of a MbUnit project file previously created with the MbUnit GUI runner. Mbunit.cons will run the tests used in the project accordingly.
- /ap or /assembly-path : Used to locate the MbUnit dlls needed to run the tests in your assembly if they aren't in the directory you're calling the runner from. assemblyPath should state the full path to the folder containing the assemblies.
- /rt or /report-type : Specifies that a report about the successes and failures of the tests should be generated. By default, no report is generated. reportType can be one of three values: text, html or xml. This report will be saved in %My Documents%\Application Data\Mbunit\Reports unless otherwise specified with the /rf option.
- /rf or /report-folder : Specifies the folder that any report generated by the console runner should be saved to. reportpath can be given as either a relative or an absolute file path.
- /rnf or /report-name-format : Specifies the name of the report file being generated by the /rt flag. By default, reportname is set to "mbunit-{0}{1}" where {0} is replaced by a long datetime string and {1} is replaced by the time (on a 24hr clock). For example mbunit-27_07_200718_08.txt.
- /tr or /transform : Specifies the location of a XSLT stylesheet to be applied to the report once it has been generated. transformpath can be given as either a relative or an absolute file path.
- /sr or /show-report : Specifies that the report should be shown by the default viewer for the report’s file type once it has been generated.
- /fc or /filter-category: Specifies that only those test fixtures decorated with the FixtureCategory attribute and categoryName will be run in this execution of MbUnit.Cons. categoryName may take the form of a comma-separated list of categories if more than one category of test should be run.
- /ec or /exclude-category: Specifies that those test fixtures decorated with the FixtureCategory attribute and categoryName will not be run in this execution of MbUnit.Cons. categoryName may take the form of a comma-separated list of categories if more than one category of test should be excluded.
- /fa or /filter-author : Specifies that only those test fixtures decorated with the Author attribute and authorName will be run in this execution of MbUnit.Cons
- /ft or /filter-type : Specifies that only those tests of the type className will be run in this execution of MbUnit.Cons. className may take the form of a comma-separated list of types if more than one types of test should be run.
- /fn or /filter-namespace : Specifies that only those tests in the named namespace will be run in this execution of MbUnit.Cons. namespace may take the form of a comma-separated list of namespaces if tests in more than one namespace should be run.
- /v or /verbose : Specifies that the command-line output from MbUnit.Cons should also include success or failure details for each test that is run.
- /sc or /shadow-copy-files : Specifies that the assemblies involved in the test run should be copied to a temporary location and run in an isolated AppDomain.
Notes
With the exception of using the /? parameter to bring up the help text, you must always call MbUnit.cons.exe from a directory that contains at least the following three MbUnit dlls
- MbUnit.Framework.dll
- QuickGraph.dll
- QuickGraph.Algorithms.dll
Use full pathnames to locate the assembly containing the tests and the assembly being tested (with the /ap switch) if they are not also in the directory you are calling MbUnit.Cons from.
The MbUnit console runner allows tests in an assembly to be grouped by author and category using the /fc, /ec and /fa flags. See here to learn about specifying test authors and categories.
The /rf, /rnf, /tr and /sr flags do nothing unless /rt is also specified.
The /fc and /ec flags only work with fixture categories as of v2.4. Support is planned to filter by test categories in a future version.
Examples
To run tests in two assemblies at once
MbUnit.Cons.exe FirstTestAssembly.dll SecondTestAssembly.dll
To run tests in the current directory against code located in c:\productioncode
MbUnit.Cons.exe TestAssembly.dll /ap:"c:\productioncode"
To run tests and generate a HTML report of the successes and failures of those tests
MbUnit.Cons.exe TestAssembly.dll /rt:html
To run tests and generate a HTML report of the successes and failures of those tests in the current directory
MbUnit.Cons.exe TestAssembly.dll /rt:html /rf:"."
To run tests and generate a HTML report of the successes and failures of those tests in the current directory in a file called MyTestReport.html
MbUnit.Cons.exe TestAssembly.dll /rt:html /rf:"." /rnf:MyTestReport
To run tests and generate a XML report of the successes and failures of those tests with a stylesheet located in the current directory applied to the report post-generation
MbUnit.Cons.exe TestAssembly.dll /rt:xml /tr:ReportTransform.xsl
To run only the test fixtures in TestAssembly.dll tagged with the fixture category "Performance"
MbUnit.Cons.exe TestAssembly.dll /fc:Performance
To run all the test fixtures in TestAssembly.dll which are not tagged with the fixture categories "Performance" or "Exceptions"
MbUnit.Cons.exe TestAssembly.dll /ec:Performance,Exceptions
To run only the test fixtures in TestAssembly.dll tagged as having the author "Andy"
MbUnit.Cons.exe TestAssembly.dll /fa:Andy
To run all the tests in TestAssembly.dll in the class TestAssembly.TestClass
MbUnit.Cons.exe TestAssembly.dll /ft:TestAssembly.TestClass
To run all the tests in TestAssembly.dll in the namespaces TestAssembly.Namespace1 and TestAssembly.Namespace2
MbUnit.Cons.exe TestAssembly.dll /fn:TestAssembly.Namespace1,TestAssembly.Namespace2
To run all the tests in TestAssembly.dll with extra commentary of the tests being run
MbUnit.Cons.exe TestAssembly.dll /v
To run all the tests in TestAssembly.dll within an isolated appDomain
MbUnit.Cons.exe TestAssembly.dll /sc
Running Tests and Reading The Results
Once you've compiled your tests and have run them through MbUnit.Cons using a combination of some, all or none of the flags above, you'll see the following standard output on the command line.
>MbUnit.Cons.exe FizzBuzzTests.dll
Parsed arguments:
-- Parsed Arguments
Files:
FizzBuzzTests.dll
Assembly paths:
Report folder:
Report Name Format: mbunit-{0}{1}Report types:
Show reports: False
Filter Category:
Exclude Category:
Filter Author:
Filter Namespace:
Filter Type:
Verbose: False
ShadowCopyFiles: False
Start time: 17:14
[info] Loading test assemblies
[info] Starting execution
[info] Sorting assemblies by dependencies
[info] Setting up fixture colors
[info] Loading FizzBuzzTests
[info] Found 4 tests
[info] Running fixtures.
[info] Tests finished: 4 tests, 4 success, 0 failures, 0 ignored
[info] All Tests finished: 4 tests, 4 success, 0 failures, 0 ignored in 0.0200288 seconds
[info] MbUnit execution finished in 0.450648s.
The output from the console runner is divided into two parts. The first, headed “Parsed arguments:” reads back to you the options you've set in the call to MbUnit.Cons.exe. In this case, there are none save the name of the test assembly being run, FizzBuzzTests.dll. The second section, headed “Start Time”, shows the progress of the runner as it tries to execute your tests. Note in particular the lines highted in red above, which tell you how many tests were run in total given the options you set - 4 in this case - how many tests were passed, ignored or failed and how long it took to run the tests.
