Pro.NBench.xUnit 1.0.5

Allows NBench tests to be discovered, executed, reported, and debugged using xUnit in ReSharper, and Visual Studio Test Explorer.

Please refer to the project Url for usage information:

https://github.com/Pro-Coded/Pro.NBench.xUnit

Install-Package Pro.NBench.xUnit -Version 1.0.5
dotnet add package Pro.NBench.xUnit --version 1.0.5
<PackageReference Include="Pro.NBench.xUnit" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pro.NBench.xUnit --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Pro.NBench.xUnit

A project to allow NBench tests to be discovered, executed, reported, and debugged using xUnit in ReSharper, and to a less polished extent, in Visual Studio Test Explorer. This allows you to not only test business logic validity, but also set performance criteria as part of your test suite.

Visual Studio 2017 Integration

Please refer to the Introduction to NBench as a starting point for information on how to configure NBench Tests and Measurements.

Installation

To install Pro.NBench.xUnit (Integration of NBench, xUnit and ReSharper / Visual Studio Test Explorer), run the following command in the Package Manager Console

    Install-Package Pro.NBench.xUnit

Usage

The Tests project serves as an example, and contains a set of three standard NBench test classes, attributed to collect Measurements, and Assert some conditions.

Step 1.

Disable xUnit parrallelized execution, at either the Assembly, or Collection level. In the example, this is achived by adding the following line within the project:

   [assembly: CollectionBehavior(DisableTestParallelization = true)]

Step 2.

Add a reference to the Pro.NBench.xUnit assembly, and include the following using statement for each class:

    using Pro.NBench.xUnit.XunitExtensions;

Step 3.

Include a constructor that includes a paramater of type ITestOutputHelper, and creates a new XunitTrace listener, as follows:

    public DictionaryMemoryTests(ITestOutputHelper output)
    {
        Trace.Listeners.Clear();
        Trace.Listeners.Add(new XunitTraceListener(output));
    }

Step 4.

Annotate each NBench test with the following attribute:

    [NBenchFact]

You can also use xUnit Theories, by adding:

    [NBenchTheory]

The NBench Tests will be discovered and displayed in either the Resharper or Visual Studio Test Runners.

Breakpoints in the NBench benchmarks are fully supported for debugging.

Please note, it is important that for accurate benchhmarking purposes, that the Tests are run in Release configuration, to allow compiler optimisations to be applied.

When executed using ReSharper, the Tests are displayed, with the result of NBench Assertions, and any Measurements reported by each Test.

ResharperResults

Visual Studio Test Explorer will also execute and debug the Tests, but presentation of results is less polished.

Please note, the example includes a variety of passing, and a deliberately failing Test.

Future plans

  • [x] Release as NuGet package.

  • [x] Integration with xUnit Theories, to support paramaterised tests.

  • [x] VS 2017, VS 2019 and JetBrains Rider support.

  • [ ] Possibly standard NBench Markdown Report output.

  • [ ] Possibly a Visual Studio Template for a pre-configured Test Project and Test Class.

--
All Feedback Welcome!

David Paul McQuiggin, Pro-Coded.

Pro.NBench.xUnit

A project to allow NBench tests to be discovered, executed, reported, and debugged using xUnit in ReSharper, and to a less polished extent, in Visual Studio Test Explorer. This allows you to not only test business logic validity, but also set performance criteria as part of your test suite.

Visual Studio 2017 Integration

Please refer to the Introduction to NBench as a starting point for information on how to configure NBench Tests and Measurements.

Installation

To install Pro.NBench.xUnit (Integration of NBench, xUnit and ReSharper / Visual Studio Test Explorer), run the following command in the Package Manager Console

    Install-Package Pro.NBench.xUnit

Usage

The Tests project serves as an example, and contains a set of three standard NBench test classes, attributed to collect Measurements, and Assert some conditions.

Step 1.

Disable xUnit parrallelized execution, at either the Assembly, or Collection level. In the example, this is achived by adding the following line within the project:

   [assembly: CollectionBehavior(DisableTestParallelization = true)]

Step 2.

Add a reference to the Pro.NBench.xUnit assembly, and include the following using statement for each class:

    using Pro.NBench.xUnit.XunitExtensions;

Step 3.

Include a constructor that includes a paramater of type ITestOutputHelper, and creates a new XunitTrace listener, as follows:

    public DictionaryMemoryTests(ITestOutputHelper output)
    {
        Trace.Listeners.Clear();
        Trace.Listeners.Add(new XunitTraceListener(output));
    }

Step 4.

Annotate each NBench test with the following attribute:

    [NBenchFact]

You can also use xUnit Theories, by adding:

    [NBenchTheory]

The NBench Tests will be discovered and displayed in either the Resharper or Visual Studio Test Runners.

Breakpoints in the NBench benchmarks are fully supported for debugging.

Please note, it is important that for accurate benchhmarking purposes, that the Tests are run in Release configuration, to allow compiler optimisations to be applied.

When executed using ReSharper, the Tests are displayed, with the result of NBench Assertions, and any Measurements reported by each Test.

ResharperResults

Visual Studio Test Explorer will also execute and debug the Tests, but presentation of results is less polished.

Please note, the example includes a variety of passing, and a deliberately failing Test.

Future plans

  • [x] Release as NuGet package.

  • [x] Integration with xUnit Theories, to support paramaterised tests.

  • [x] VS 2017, VS 2019 and JetBrains Rider support.

  • [ ] Possibly standard NBench Markdown Report output.

  • [ ] Possibly a Visual Studio Template for a pre-configured Test Project and Test Class.

--
All Feedback Welcome!

David Paul McQuiggin, Pro-Coded.

Version History

Version Downloads Last updated
1.0.5 85 4/16/2019
1.0.4 8,853 2/27/2018
1.0.3 1,143 7/31/2017
1.0.2 776 8/4/2016
1.0.1 407 8/4/2016
1.0.0-Pre 436 8/1/2016