Lightweight testing helpers for single-file C# programs and scripts.
Jaribu (Swahili: test/trial) provides a convention-based TestRunner pattern and assertion helpers for executable .cs files. It enables easy testing in single-file scenarios without heavy test frameworks.
- Convention over Configuration: Discover public static async Task methods as tests via reflection.
- Assertion Helpers: Simple, fluent assertions inspired by Shouldly.
- Attributes: Support for [Skip], [TestTag], [Timeout], [Input], and [ClearRunfileCache].
- Parameterized Tests: Easy data-driven testing.
- Tag Filtering: Run specific test groups.
- Cache Management: Clear runfile cache for consistent testing.
- Minimal Dependencies: Only Shouldly for assertions.
Add the NuGet package:
dotnet add package TimeWarp.Jaribu
Create a single-file test script (e.g., my-tests.cs):
using static TimeWarp.Jaribu.TestHelpers;
public static class MyTests
{
public static async Task BasicTest()
{
1.ShouldBe(1);
}
[TestTag("integration")]
public static async Task IntegrationTest()
{
// Test logic here
}
}Run with:
dotnet run --project my-tests.cs
For programmatic use:
using TimeWarp.Jaribu;
await TestRunner.RunTests<MyTests>();Define Setup() and CleanUp() methods to run code before and after each test:
public static class MyTests
{
public static async Task Setup()
{
// Runs before EACH test
// Initialize test data, create temp files, etc.
await Task.CompletedTask;
}
public static async Task CleanUp()
{
// Runs after EACH test
// Clean up resources, delete temp files, etc.
await Task.CompletedTask;
}
public static async Task Test1()
{
// Setup runs before this test
// Test logic here
// CleanUp runs after this test
}
public static async Task Test2()
{
// Setup runs before this test (fresh state)
// Test logic here
// CleanUp runs after this test
}
}Note: For one-time initialization, use static constructors or static field initialization:
public static class MyTests
{
private static readonly ExpensiveResource Resource = InitializeResource();
private static ExpensiveResource InitializeResource()
{
// One-time initialization
return new ExpensiveResource();
}
}See the developer documentation for advanced usage, attributes, and best practices.
- Clone the repository.
- Run
dotnet build. - Run tests with
dotnet run --project Tests/TimeWarp.Jaribu.Tests/TimeWarp.Jaribu.Tests.csproj.
Contributions welcome! See CONTRIBUTING.md for guidelines.