maple-TestHelpers
1.1.2
dotnet add package maple-TestHelpers --version 1.1.2
NuGet\Install-Package maple-TestHelpers -Version 1.1.2
<PackageReference Include="maple-TestHelpers" Version="1.1.2" />
<PackageVersion Include="maple-TestHelpers" Version="1.1.2" />
<PackageReference Include="maple-TestHelpers" />
paket add maple-TestHelpers --version 1.1.2
#r "nuget: maple-TestHelpers, 1.1.2"
#:package maple-TestHelpers@1.1.2
#addin nuget:?package=maple-TestHelpers&version=1.1.2
#tool nuget:?package=maple-TestHelpers&version=1.1.2
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)
Links
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:
TheorySkipOnOSAttributefor 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 | Versions 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. |
-
net8.0
- Testably.Abstractions (>= 10.2.0)
- xunit (>= 2.9.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.