Skip to content

Runners

Averrunci edited this page Jun 7, 2022 · 8 revisions

Console Runner

Installation

.NET Framework 4.6

Runs the following command in the Package Manager Console.

PM> Install-Package CarnaConsoleRunner

.NET Core

  1. Creates the console application.
> dotnet new console
  1. Adds the Carna.ConsoleRunner package.
> dotnet add package Carna.ConsoleRunner
  1. Fixes Program.cs as follows.
using Carna.ConsoleRunner;

namespace Lib.Spec
{
    static class Program
    {
        static int Main(string[] args) => CarnaConsoleRunner.Run(args);
    }
}
  1. Adds "carna-runner-settings.json" file.
{
  "assemblies": [
    "Lib.Spec.dll"
  ],
  "reporters": [
    {
      "reporter": {
        "type": "Carna.ConsoleRunner.Reporters.ConsoleFixtureReporter,Carna.ConsoleRunner",
        "options": {
          "stepVisible": true
        }
      }
    }
  ]
}

.NET Tool

  1. Creates a tool manifest file.
> dotnet new tool-manifest
  1. Installs the carna-runner.
> dotnet tool install carna-runner
  1. Adds the CopyLocalLockFileAssemblies section in the project file as follows.
<PropertyGroup>
  <TargetFramework>netstandard2.0</TargetFramework>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
  1. Adds the PrivateAssets and the ExcludeAssets section in the project file as follows.
<ItemGroup>
  <PackageReference Include="Carna" Version="1.7.2">
    <PrivateAssets>all</PrivateAssets>
    <ExcludeAssets>runtime</ExculdeAssets>
  </PackageReference>
</ItemGroup>

Usage

(.NET Framework 4.6)

> CarnaConsoleRunner.exe [options] [assembly file]

(.NET Core)

> dotnet run [options] [assembly file]

(.NET Tool)

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

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

Options

/settings:<path>

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

/filter:<patter>

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

/nodomain

Specifies that no domain is created and the fixtures are run in the primary domain. If not specified, the separate domain is created for each assembly and the fixtures are run in it.

/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:

> CarnaConsoleRunner.exe /f:T.+Story Lib.Spec.dll Core.Spec.dll
> CarnaConsoleRunner.exe /s:settings.json

Carna UWP Runner

Installation

  1. Creates the Blank App (Universal Windows).

  2. Adds the Carna.UwpRunner package.

PM> Install-Package Carna.UwpRunner
  1. Fixes App.xaml.cs as follows.
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;

using Carna.UwpRunner;

namespace Lib.Spec
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Window.Current.Activate();
            CarnaUwpRunner.Run();
        }
    }
}
  1. Adds "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 CarnaUwpRunner 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 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 IDictionary<string, string>.

For example:

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

Carna WinUI Runner

Installation

  1. Creates the Blank App (WinUI).

  2. Adds the Carna.WinUIRunner package.

PM> Install-Package Carna.WinUIRunner
  1. Fixes App.xaml.cs as follows.
using Windows.UI.Xaml;

using Carna.WinUIRunner;

namespace Lib.Spec
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            CarnaWinUIRunner.Run();
        }
    }
}
  1. Adds "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 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 IDictionary<string, string>.

For example:

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