TimeWarp.Fixie 1.0.2

This package has a SemVer 2.0.0 package version: 1.0.2+7.0.100.
dotnet add package TimeWarp.Fixie --version 1.0.2
NuGet\Install-Package TimeWarp.Fixie -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TimeWarp.Fixie" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TimeWarp.Fixie --version 1.0.2
#r "nuget: TimeWarp.Fixie, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TimeWarp.Fixie as a Cake Addin
#addin nuget:?package=TimeWarp.Fixie&version=1.0.2

// Install TimeWarp.Fixie as a Cake Tool
#tool nuget:?package=TimeWarp.Fixie&version=1.0.2

Dotnet Stars Discord nuget nuget Issues Open Forks License Twitter

Twitter Twitter

timewarp-fixie

TimeWarp Logo

Fixie is a .NET test framework similar to NUnit and xUnit, but with an emphasis on low-ceremony defaults and flexible customizations.

TimeWarp-fixie is a project that uses conventions to simplify using Fixie even further.

Feature overview

  • Dependency Injection support for test cases.
  • No need to decorate test methods with [Test] attributes. Public methods are test cases by default.
  • Skip - can mark tests to be skipped.
  • Tags - Add tags to your tests and filter runs based on the tag.
  • Inputs - Allow for parameterized tests. (similar to how "Theory" works in xUnit)
  • Lifecycle Methods - if the Setup or Cleanup methods are found on the test class they will be executed appropriately.
  • NotTest - Can mark methods with NotTest attribute if they are not tests.
  • Filter tests by name
  • Filter tests by Tags

Give a Star! ⭐

If you like or are using this project please give it a star. Thank you!

Installation

You can see the latest NuGet packages from the official TimeWarp NuGet page.

Usage

Create a new test project.

dotnet new classlib -n MyProject.Tests

Add Nugets to the project

dotnet add package TimeWarp.Fixie
dotnet add package Fixie.TestAdapter --version 3.2.0

Create a dotnet tool manifest.

dotnet new tool-manifest

Add Fixie.Console to the manifest

dotnet tool install Fixie.Console

Inside your fixie project create a class that inherits from Fixie.Conventions.TestConvention

class TestProject : TimeWarp.Fixie.TestingConvention { }

This will then use the TimeWarp.Fixie convention.

Create a sample test. First we will add FluentAssertions you could use basic Asserts or any other assertion library.

dotnet add package FluentAssertions --version 6.7.0

Create a sample test case.

namespace ConventionTest_;

using FluentAssertions;
using TimeWarp.Fixie;

[TestTag(TestTags.Fast)]
public class SimpleNoApplicationTest_Should_
{
  public static void AlwaysPass() => true.Should().BeTrue();

  [Skip("Demonstrates skip attribute")]
  public static void SkipExample() => true.Should().BeFalse();

  [TestTag(TestTags.Fast)]
  public static void TagExample() => true.Should().BeTrue();

  [Input(5, 3, 2)]
  [Input(8, 5, 3)]
  public static void Subtract(int aX, int aY, int aExpectedDifference)
  {
    int result = aX - aY;
    result.Should().Be(aExpectedDifference);
  }
}

Execute the tests:

dotnet fixie

Features

Dependency Injection

Tests are instantiated from the dependency injection container set up for tests. So you can use the same pattern for testing as we use for production apps.

No need to decorate test methods with [Test] attributes. Public methods are test cases by convention.

// Xunit style
[Test] // <==== Not needed with TimeWarp Fixie Convention
public void SomeTest()
{
  Assert.Fail();
}
// TimeWarp Fixie Convention all public methods are tests 
public void SomeTest()
{
  Assert.Fail();
}

Skip - can mark tests to be skipped

  [Skip("Reason for skipping")]
  public static void SkipExample() => true.Should().BeFalse();

Tags

You can add tags to any of your tests. We include some we use in the TestTags static class but they are just strings so you can add whatever you like.

  [TestTag(TestTags.Fast)]
  [TestTag("Bug123")]
  public static void TagExample() => true.Should().BeTrue();

Parameterized tests

Similar to how xUnit uses [Theory] you can run a test for each set of parameters.

  [Input(5, 3, 2)]
  [Input(8, 5, 3)]
  public static void Subtract(int aX, int aY, int aExpectedDifference)
  {
    int result = aX - aY;
    result.Should().Be(aExpectedDifference);
  }

Lifecycle Methods

If the Setup or Cleanup methods are found on the test class they will be executed appropriately for each test.

public class LifecycleExamples
{
  public static void AlwaysPass() => true.Should().BeTrue();

  [Input(5, 3, 2)]
  [Input(8, 5, 3)]
  public static void Subtract(int aX, int aY, int aExpectedDifference)
  {
    // Will run lifecycles around each Input
    int result = aX - aY;
    result.Should().Be(aExpectedDifference);
  }

  public static void Setup() => Console.WriteLine("Sample Setup");
  public static void Cleanup() => Console.WriteLine("Sample Cleanup");
}

NotTest

If you have a class that needs to be public that does not contain tests you can mark it as such with the [NotTest] attribute.

An example where we use this is in the declaration of the NotTest Attribute itself

[NotTest]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class NotTest : Attribute { }

How to filter tests by Name

From fixie docs

The optional argument --tests (abbreviated -t) lets you specify which tests to run.

A full test name match will run that single test:

dotnet fixie MyTestProject --tests Full.Namespace.MyTestClass.MyTestMethod

To avoid having to type the full namespace or method name, there is an implicit wildcard at the start and end of the pattern. Here we run an entire test class:

dotnet fixie MyTestProject --tests MyTestClass

There is an implicit lowercase letter wildcard, whenever a capital letter is followed by a non-lowercase character. In other words, you can type "MTC" to match "MyTestClass". Here we run a select few related tests within that class:

dotnet fixie MyTestProject --tests MTC.ShouldValidateThat

Although unnecessary in most realistic cases, an explicit * wildcard will match any sequence of zero or more characters:

dotnet fixie MyTestProject --tests MTC.*Validate

When all tests are run by omitting the --tests argument, passing tests are omitted for brevity. However, because a --tests pattern may in fact be more inclusive than the developer intended, the console output will include passing test names in addition to other test results as feedback whenever this argument is used.

How to filter tests by Tags

If you want to only run tests with a given tag/s you can do this by passing in the --Tag parameter after --. If you want to run more than one Tag pass the parameter multiple times.

Examples:

dotnet fixie --no-build -- --Tag Fast --Tag Smoke
dotnet fixie -- --Tag Smoke

Unlicense

License

Contributing

Time is of the essence. Before developing a Pull Request I recommend opening a discussion.

Please feel free to make suggestions and help out with the documentation. Please refer to Markdown for how to write markdown files.

Contact

Sometimes the github notifications get lost in the shuffle. If you file an issue and don't get a response in a timely manner feel free to ping on our Discord server.

Discord

References

https://github.com/fixie/fixie

Commands used

dotnet new sln
dotnet new classlib -n timewarp-fixie
dotnet new classlib -n TimeWarp.Fixie.Tests
dotnet sln add .\source\timewarp-fixie\timewarp-fixie.csproj
dotnet new tool-manifest
dotnet tool install dotnet-cleanup
dotnet tool install Fixie.Console
dotnet cleanup -y
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on TimeWarp.Fixie:

Repository Stars
TimeWarpEngineering/blazor-state
A Blazor State management library by TimeWarp.
Version Downloads Last updated
1.0.2 860 11/26/2022
1.0.1 470 10/26/2022
1.0.0 343 10/26/2022
1.0.0-alpha.2 86 10/6/2022
1.0.0-alpha.1 122 8/19/2022
1.0.0-alpha.0 111 8/1/2022