Using the dotnet Command Line Utility to Manage Unit Testing Projects

The following commands are examples of the main actions when managing unit testing projects in a .NET 8 environment. Further arguments can be used with these commands. Use the -h argument to show the full list of options; for example dotnet new mfunit -h.

Create a new unit testing project
The following command creates a new unit testing project file (.cblproj) named after the current working directory. containing a number of default settings.
dotnet new mfunit
Create a new test fixture file
The following command creates a new test fixture file called TestSimpleTest.cbl in the current working directory. (The default setting from the installed template is to prefix fixture files with 'Test'.)
dotnet new mfunit-test --test-case SimpleTest
Create a new test fixture file for a data driven test
The following command creates a new test fixture file called TestDataDTest.cbl in the current working directory. It also creates a .csv file of the same name, in which to populate your test data. The test fixture file also contains the required linkage for the test cases to use the data file.
dotnet new mfunit-dd-test --test-case DataDTest
Reference an external project
If a test case references external code, you must add a reference to that code's project. During a build, the restore process will update its external references, to ensure you are using the latest code in your test cases. The following command adds a reference to the specified project, in the local project.
dotnet add reference <path/external.cblproj>

where <path/external.cblproj> is the path and file name of the external project file.

Warning: Each fixture file referenced in a build must have a unique program name, otherwise the build generates an error.
Create a test fixture file that references an external program
As well as creating a project reference, you also need to pre-load the assembly containing the referenced program when you run the test case. The following command sets up the procedure pointer in the TestSimpleTest fixture file that is required to call into the external source:
dotnet new mfunit-test --test-case SimpleTest --pre-load-library <external-assembly>

where <external-assembly> is the name of the assembly as built in the external project. The new test case is created that contains a correctly configured procedure pointer, which is required for calling into the external source.

Building a unit test project
The following command builds the unit testing project using the .cblproj file in the current working directory. By default, the output is build to the /bin/Debug/net8.0 sub-directory.
dotnet build
Running a unit test project
The following command runs the unit testing project that has been built to the output directory specified in the .cblproj file in the current working directory. This is the equivalent of using the .NET 8 test runner command (see Test Runner Syntax Options for more information).
dotnet run
Note: This option can be disabled when a new project is created by using the --enable-dotnet-run-command false; in which case, you must use the test runner command to run your tests.