Lightweight unit test framework for C# written from scratch.
It consists of 2 components:
- MiniTest library - containing test attributes allowing users to mark classes and methods as test containers and assertion methods.
- MiniTestRunner executable - an application that dynamically loads assemblies containing tests, searches for test containers, executes found tests, and presents the test results in the console.
The library provides the following attributes used to mark classes and methods as test containers and manage the test lifecycle.
- TestClassAttribute marks a class as a container for test methods.
- TestMethodAttribute marks a method as a unit test to be executed.
- BeforeEachAttribute defines a method to be executed before each test method.
- AfterEachAttribute defines a method to be executed after each test method.
- PriorityAttribute sets a priority (integer) for test prioritization, with lower numerical values indicating higher priority.
- DataRowAttribute enables parameterized testing by supplying data to test methods.
- it accepts an array of objects (
object?[]) representing test data. - optionally takes a string parameter that documents the test data set.
- it accepts an array of objects (
- DescriptionAttribute allows the inclusion of additional description to a test or a test class.
The library also provides methods to verify test success or failure conditions.
ThrowsException<TException>(Action action, string message = ""): Confirms that a specific exception type is thrown during a given operation.AreEqual<T>(T? expected, T? actual, string message = ""): Verifies equality between expected and actual values.AreNotEqual<T>(T? notExpected, T? actual, string message = ""): Ensures that the expected and actual values are distinct.IsTrue(bool condition, string message = ""): Confirms that a boolean condition is true.IsFalse(bool condition, string message = ""): Confirms that a boolean condition is false.Fail(string message = ""): Explicitly fails a test with a custom error message.
Additionally, all methods take an optional message string that describes the purpose of the assertion.
An example implementation of IsTrue:
public static void IsTrue(bool condition, string message = "")
{
if (!condition)
{
throw new AssertionException(message);
}
}
AuthenticationService.Tests already includes tests marked with attributes described earlier.
Can be used as an example
The MiniTestRunner is a console application that handles the discovery and execution of tests, providing output and summaries upon completion.
The application takes the assembly file paths as command-line arguments. These assemblies should contain the test classes and methods defined using the MiniTest framework.
Example:
MiniTestRunner path/to/test-assembly1.dll path/to/test-assembly2.dll
Methods are executed in order based on the PriorityAttribute, where a lower numerical value indicates a higher priority. Methods without the attribute have a priority of 0. Methods with the same priority should be executed in alphabetical order based on the method name.
For each test class, for each test, runner executes:
BeforeEachmethod- The test method itself
AfterEachmethod
In parameterized tests, each data row provided via DataRowAttribute is executed separately (counts as a separate test), passing the specified parameters to the test method.
Test counts as failed if, during the execution of the test method, an unhandled exception was thrown.
Output shown for each test:
- Test status:
PASSEDorFAILED. - Failure reasons and exception messages for failed tests.
- Output the description (if provided) for the class or test method.
Output shown for each class:
- Total number of tests in a class.
- Number of passed and failed tests in a class.
After running all tests from an assembly, summary is shown.
Output is colorized for better readability:
- Green for passed tests.
- Red for failed tests.
- Yellow for test-related warnings (e.g., incompatible configuration, no parameterless constructor).
Project was made for Programming 3 - advanced classes

