maple-TestHelpers 1.1.2

dotnet add package maple-TestHelpers --version 1.1.2
                    
NuGet\Install-Package maple-TestHelpers -Version 1.1.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="maple-TestHelpers" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="maple-TestHelpers" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="maple-TestHelpers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add maple-TestHelpers --version 1.1.2
                    
#r "nuget: maple-TestHelpers, 1.1.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.
#:package maple-TestHelpers@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=maple-TestHelpers&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=maple-TestHelpers&version=1.1.2
                    
Install as a Cake Tool

TestHelpers Project

Description

Library that implements helper functionality typically required in xunit test projects.

Download NuGet Package

dotnet add package maple-TestHelpers

Or for .NET 10 / xUnit 3.x support:

dotnet add package maple-TestHelpers.v3

Examples

namespace TestHelpers.Files

FileGarbageCollector

Automatically clean up test files created during test execution.

public class MyTests
{
    private readonly FileGarbageCollector _fileCollector;

    public MyTests(ITestOutputHelper outputHelper)
    {
        _fileCollector = new FileGarbageCollector(outputHelper);
    }

    [Fact]
    public void TestCreatesFile()
    {
        string testFile = Path.Combine(Path.GetTempPath(), "test.txt");
        File.WriteAllText(testFile, "test content");

        // Register file for cleanup
        _fileCollector.RegisterFile(testFile);

        // Your test logic...
    }

    // Cleanup is called automatically when the test completes
    void IAsyncLifetime.DisposeAsync() => _fileCollector.Dispose();
}

FactSkipOnOSAttribute

Allow skipping fact tests based on the OS the tests are running.

[FactSkipOnOS(OS.Windows)]
public void TestMethod()
{
	// This test will be skipped on Windows
}

TheorySkipOnOSAttribute

Allow skipping theory tests based on the OS the tests are running.

[TheorySkipOnOS(OS.Linux_based)]
[InlineData(1)]
[InlineData(2)]
public void TestMethod(int value)
{
	// These theory tests will be skipped on Linux-based systems
}

OSPathNormalizer

Normalize Windows-style paths to the current OS when tests run on Linux.

using static TestHelpers.Files.OSPathNormalizer;

// use windows style paths
var path = X(@"c:\temp\..\temp\file.txt");

TestDataHelper

Resolve test data files and directories with automatic validation.

// Resolve a test file with validation (throws if not found)
string filePath = TestDataHelper.ResolveTestdataFile("testdata.xml");

// Resolve a test file without validation
string filePath = TestDataHelper.ResolveTestdataFile("optional.xml", validateExistence: false);

// Resolve a test directory
string dirPath = TestDataHelper.ResolveTestdataDirectory("testdata/");

// Access the test data directory directly
string testDataDir = TestDataHelper.TestDataDirectory;

The ResolveTestdataFile method performs case-sensitive path validation to catch casing issues early, which is important for cross-platform tests that run on both Windows and Linux.

Path.BuildTempFileName (TestHelpers.v3 only)

Build a fully qualified temporary file path in the OS temp directory.

using System.IO;

string tempFile = Path.BuildTempFileName("subfolder/testfile.tmp");
// Returns: C:\Users\user\AppData\Local\Temp\subfolder\testfile.tmp (Windows)
// Returns: /tmp/subfolder/testfile.tmp (Linux)

Release Notes

Re-enabling that paths can be specified with forward and backward slashes on all platforms

  • This was a regression in v1.1 that caused issues with test data file resolution.

Latest Features

  • Case-Sensitive Path Validation: TestDataHelper.ResolveTestdataFile() now detects and reports path casing errors, helping catch cross-platform test issues early
  • Temporary File Helper: Path.BuildTempFileName() extension method for building qualified paths in the OS temp directory (TestHelpers.v3 only)
  • Theory Test Skip Support: TheorySkipOnOSAttribute for skipping theory-based tests on specific operating systems
  • Improved Path Normalization: OSPathNormalizer.X() for consistent Windows-style path handling across platforms

Version Information

  • TestHelpers - .NET 8.0 support, xUnit 2.x compatible
  • TestHelpers.v3 - .NET 10.0 support, xUnit 3.x compatible

Troubleshooting

Test fails with "File path has incorrect casing"

  • Ensure test data files use the correct casing as they exist in the file system
  • This check is intentional for cross-platform compatibility

Path normalization not working on Windows

  • Use OSPathNormalizer.SwitchToLinux() in test setup to simulate Linux behavior
  • Call OSPathNormalizer.Reset() in test cleanup to restore original behavior
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 135 5/15/2026
1.1.1 113 5/15/2026
1.1.0 113 5/14/2026
1.0.6 133 3/23/2026
1.0.5.2 234 6/18/2025
1.0.4.1 197 12/2/2024
1.0.4 197 12/2/2024
1.0.3 207 12/2/2024
1.0.2 200 12/2/2024
1.0.1.1 207 9/2/2024
1.0.0 276 1/14/2024