StellaTesting 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package StellaTesting --version 1.0.1                
NuGet\Install-Package StellaTesting -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StellaTesting" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StellaTesting --version 1.0.1                
#r "nuget: StellaTesting, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StellaTesting as a Cake Addin
#addin nuget:?package=StellaTesting&version=1.0.1

// Install StellaTesting as a Cake Tool
#tool nuget:?package=StellaTesting&version=1.0.1                

Stella Testing: A Lightweight, Reflection-Based C# Testing Library

Features

  • Simplicity: Write tests as regular methods with the [ST_TEST] attribute.
  • Flexibility: Execute tests from your main application or discover and run tests across all loaded assemblies.
  • Extensibility: Easily integrate with C# REPLs or add testing capabilities to your executables.
  • Clear Output: Color-coded results for easy identification of passed and failed tests.

Installing

dotnet add package StellaTesting

How To Use

1. Import the namespace

using Stella.Testing;

2. Create functions with the [ST_TEST] annotation

You can turn any function into a test with [ST_Test] but it must return an TestingResult object.

public class TestingResult(string errorMessage, bool passed)
{
    public string ErrorMessage = errorMessage;
    public bool Passed = passed;

    //Automatically formats a pretty string of the test result ready to be printed to the console!
    public string PrettyToString()
    {
        string status = Passed ? "Passed [✓]" : "Failed [X]";
        return $"{status} : {ErrorMessage}";
    }
}

Stella Testing provides some assert helper function that each return a TestingResult object

...
[ST_TEST]
private static TestingResult TestMyMethod()
{
    // Your test logic here
    return AssertEqual(expectedValue, actualValue, "MyMethod failed");
}
...

Stella Testing provides convenient assertion functions:

  • AssertEqual<T>(expected, actual, message)
  • AssertTrue(condition, message)
  • AssertFalse(condition, message)

3. Run Tests

You can either run all tests that you defined in you main application or you can all tests found in your project as well as any dependencies that might defined tests too.

StellaTesting.RunTests();
StellaTesting.RunAllTestsFoundInAllAssemblies();

Why Another Testing-Library/Framework?

Simple, I wanted to write my tests right next to the implementation, now I can write the test methods besides the implemenation method or create a test_class.cs and write them there. With the ability to simply call StellaTesting.RunTests(). I personally use this (C# REPL)[https://github.com/waf/CSharpRepl] and having the ability to run all tests in the REPL is quite powerful.

  • No Dependency on Visual-Studio
  • No Test Runner
  • Simple function call to run tests.
  • Ability to run all tests found in all assemblies (of course only those whose uses this library)

And its trival to add the possiblity to run tests in your executable

static void Main(string[] args)
{
    if (args.Length > 0 && args[0] == "--run-tests")
    {
        StellaTesting.RunTests();
        return;  // Exit after running tests
    }

    // ... your normal application logic
}

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on StellaTesting:

Package Downloads
StellaSockets

A lightweight C# wrapper around a lightweight nng c wrapper that provides some higher abstractions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 90 7/26/2024
1.0.1 52 7/26/2024
1.0.0 52 7/26/2024

Initial release.