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

Copy 
MbUnit.Cons.exe
Copy 
MbUnit.Cons.exe /?
Copy 
MbUnit.Cons.exe /help

Full Syntax

Copy 
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

Copy 
MbUnit.Cons.exe FirstTestAssembly.dll SecondTestAssembly.dll

To run tests in the current directory against code located in c:\productioncode

Copy 
MbUnit.Cons.exe TestAssembly.dll /ap:"c:\productioncode" 

To run tests and generate a HTML report of the successes and failures of those tests

Copy 
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

Copy 
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

Copy 
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

Copy 
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"

Copy 
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"

Copy 
MbUnit.Cons.exe TestAssembly.dll /ec:Performance,Exceptions

To run only the test fixtures in TestAssembly.dll tagged as having the author "Andy"

Copy 
MbUnit.Cons.exe TestAssembly.dll /fa:Andy

To run all the tests in TestAssembly.dll in the class TestAssembly.TestClass

Copy 
MbUnit.Cons.exe TestAssembly.dll /ft:TestAssembly.TestClass

To run all the tests in TestAssembly.dll in the namespaces TestAssembly.Namespace1 and TestAssembly.Namespace2

Copy 
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

Copy 
MbUnit.Cons.exe TestAssembly.dll /v

To run all the tests in TestAssembly.dll within an isolated appDomain

Copy 
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.

Copy 
>MbUnit.Cons.exe FizzBuzzTests.dll
Copy 
Parsed arguments:
Copy 
-- Parsed Arguments
Copy 
Files:
Copy 
FizzBuzzTests.dll
Copy 
Assembly paths:
Copy 
Report folder:
Copy 
Report Name Format: mbunit-{0}{1}
Copy 
Report types:
Copy 
Show reports: False
Copy 
Filter Category:
Copy 
Exclude Category:
Copy 
Filter Author:
Copy 
Filter Namespace:
Copy 
Filter Type:
Copy 
Verbose: False
Copy 
ShadowCopyFiles: False
Copy 
Copy 
Start time: 17:14
Copy 
[info] Loading test assemblies
Copy 
[info] Starting execution
Copy 
[info] Sorting assemblies by dependencies
Copy 
[info] Setting up fixture colors
Copy 
[info] Loading FizzBuzzTests
Copy 
[info] Found 4 tests
Copy 
[info] Running fixtures.
Copy 
[info] Tests finished: 4 tests, 4 success, 0 failures, 0 ignored
Copy 
[info] All Tests finished: 4 tests, 4 success, 0 failures, 0 ignored in 0.0200288 seconds
Copy 
[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.