namespace Titano.Testing;
/// Marks a public method as a test. The method may be sync or return /.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class TestAttribute : Attribute;
/// Marks a parameterised test; each is one execution.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class TheoryAttribute : Attribute;
/// One set of arguments for a test.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class CaseAttribute(params object?[] arguments) : Attribute
{
public object?[] Arguments { get; } = arguments ?? [null];
/// Optional display name for the case.
public string? Name { get; init; }
}
/// Skips a test (or every test of a class) with a reason.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public sealed class SkipAttribute(string reason) : Attribute
{
public string Reason { get; } = reason;
}
/// Fails the test when it runs longer than the given number of milliseconds.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public sealed class TimeoutAttribute(int milliseconds) : Attribute
{
public int Milliseconds { get; } = milliseconds;
}
/// Tags a test or class; filters accept category:name.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public sealed class CategoryAttribute(string name) : Attribute
{
public string Name { get; } = name;
}
/// Runs only on Windows; skipped elsewhere.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
public sealed class WindowsOnlyAttribute : Attribute;
/// Runs only when the environment variable is set and non-empty; skipped otherwise.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public sealed class RequiresEnvironmentAttribute(string variable) : Attribute
{
public string Variable { get; } = variable;
}
/// Tests of this class never run concurrently with any other test.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class SerialAttribute : Attribute;