Carna

Runners

Console Runner

Installation

.NET Tool
  1. Creates a tool manifest file.
    > dotnet new tool-manifest
  2. Installs the carna-runner.
    > dotnet tool install carna-runner
  3. Adds the CopyLocalLockFileAssemblies section in the project file as follows.
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    </PropertyGroup>
  4. Adds the IncludeAssets section in the project file as follows.
    <ItemGroup>
        <PackageReference Include="Carna" Version="3.0.0">
            <IncludeAssets>compile</IncludeAssets>
        </PackageReference>
    </ItemGroup>
  5. Adds the "carna-runner-settings.json" file.
    {
        "assemblies": [
            "Lib.Spec.dll"
        ],
        "reporters": [
            {
                "reporter": {
                    "type": "Carna.ConsoleRunner.Reporters.ConsoleFixtureReporter,carna-runner",
                    "options": {
                        "stepVisible": true
                    }
                }
            }
        ]
    }
.NET
  1. Creates the console application.
    > dotnet new console
  2. Adds the Carna.ConsoleRunner package.
    > dotnet add package Carna.ConsoleRunner
  3. Fixes the Program.cs file as follows.
    using Carna.ConsoleRunner;
    
    namespace Lib.Spec;
                
    internal static class Program
    {
        private static int Main(string[] args) => CarnaConsoleRunner.Run(args);
    }
  4. Adds the "carna-runner-settings.json" file.
    {
        "assemblies": [
            "Lib.Spec.dll"
        ],
        "reporters": [
            {
                "reporter": {
                    "type": "Carna.ConsoleRunner.Reporters.ConsoleFixtureReporter,Carna.ConsoleRunner",
                    "options": {
                        "stepVisible": true
                    }
                }
            }
        ]
    }

Usage

(.NET Tool)

> dotnet carna-runner [options] [assembly file]

(.NET Core)

> dotnet run [options] [assembly file]

If an assembly or settings file is not specified, the console runner uses the settings file whose name is "carna-runner-settings.json" in the current working directory.

Options

--settings:<path>

Specifies the path of the carna runner settings file. (Short form: -s)

--filter:<patter>

Specifies the pattern of the full name of the fixture method or the tag of the fixture with the regular expression. (Short form: -f)

--pause

Specifies to wait for a user input before running the fixtures, allowing to attach a debugger. (Short form: -p)

--help

Displays the usage message. (Short form: -h or -?)

For example:

> dotnet carna-runner -f:T.+Story Lib.Spec.dll Core.Spec.dll
> dotnet carna-runner -s:settings.json

Carna WinUI Runner

Installation

  1. Creates the Blank App (WinUI).
  2. Adds the Carna.WinUIRunner package.
    PM> Install-Package Carna.WinUIRunner
  3. Fixes the App.xaml.cs file as follows.
    using Microsoft.UI.Xaml;
    using Carna.WinUIRunner;
    
    namespace Lib.Spec;
    
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }
    
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            CarnaWinUIRunner.Run();
        }
    }
  4. Adds the "carna-runner-settings.json" file as Content and specifies the assembly name.
    {
        "assemblies": [
            "Lib.Spec.exe"
        ]
    }

Configuration

In addition to the default options, the following options can be specified.

autoExit

Type: boolean

Specifies the value that indicates whether to exit the application automatically after the running of CarnaWinUIRunner is completed. The default value is false.

For example:

{
    "autoExit": true
}
formatter

Type: Object

Specifies the formatter to format a fixture running result.

type

Type: String

Specifies the assembly-qualified name of the formatter that implements the IFixtureFormatter interface.

options

Type: Object

Specifies options for the formatter. The options property is applied if the formatter class has a constructor that has a parameter of the IDictionary<string, string>.

For example:

{
    "formatter": {
        "type": "Carna.Runner.Formatters.FixtureFormatter"
    }
}