Dotnet Test Runner For The Rest Of Us (tm)
- You have a small library with a modest set of tests.
- You don't care about "test explorer" or whatnot, but rather want to have a simple console application to run your tests.
- You don't want to add fat loaders scanning your assemblies because they slow down the debugger launch.
- You are too stupid and/or lazy to understand everything the bigger test frameworks do under the hood
https://www.nuget.org/packages/TrivialTestRunner/ - or add TrivialTestRunner.cs to your project
In your test console application (where classes TestClass1 and TestClass2 contain the test methods):
using TrivialTestRunner
static anync Task Main(string[] args)
{
TRunner.AddTests<TestClass1>();
TRunner.AddTests<TestClass2>();
await TRunner.RunTestsAsync();
// write results to console
TRunner.ReportAll();
}
In your test classes:
// normal case
[Case]
public static void Test1()
{
Assert.IsTrue(true);
}
// normal non static case
[Case]
public void Test2()
{
Assert.IsTrue(true);
}
// normal non static async case
[Case]
public async Task Test3()
{
Assert.IsTrue(true);
return await Task.CompletedTask;
}
// focused case
[fCase]
public static void Test3()
{
Assert.IsTrue(true);
}
Note that one of the tests is "focused", i.e. fCase. If there are any focused tests in your set, only the focused tests will be run (yes, this means you don't need that "test explorer" to launch tests one by one)
If you want not to catch exceptions while running the tests (i.e. you want to trigger the debugger when it happens), do:
// CrashHard will raise exception all the way
TRunner.CrashHard = true;
MIT