Tasty is a .NET library that runs delicious dotnet tests and is inspired by jest, bullseye and simple-exec.
Tasty can do anything. It's not restricted to be a testing framework.
Platform support: .NET Standard 2.0 and upwards, including net462.
Tasty doesn't have any strong opinion in which context you are running tests from. For this tutorial we are going to start with a simple console application:
dotnet new console -o MyFirstTastyTests && cd MyFirstTastyTests
Tasty is a micro framework, so think of it more as a library than a whole framework. In order to use Tasty we need to add the nuget package:
dotnet add package Xenial.Tasty
Tasty uses the C#6 syntax to reduce clutter when writing tests, so we need to add a static using import to use it:
using System;
using static Xenial.Tasty; //This will import all the static methods into the current namespace
namespace MyFirstTastyTests
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
}
Tasty is a functional inspired testing micro framework that uses the latest C# features like Tuples and inline functions to increase test readability and provide richer error messages for better UX when troubleshooting failing tests. So let's add a simple calculation test:
using System;
using static Xenial.Tasty;
namespace MyFirstTastyTests
{
class Program
{
static void Main(string[] args)
{
//This will tell Tasty that there is an test case named '1 + 2 should be 3'
It("1 + 2 should be 3", () =>
{
var calculation = 1 + 2; // Act
var isThree = calculation == 3; // Assert
//Tell Tasty the result by returning a Tuple with additional information
return (isThree, $"1 + 2 should be 3 but actually was {calculation}");
});
}
}
}
Because Tasty is a micro framework. That means it does nothing until you tell it to do so. So let's add the Run
method and tell it to execute the tests:
using System;
using static Xenial.Tasty;
namespace MyFirstTastyTests
{
class Program
{
static void Main(string[] args)
{
It("1 + 2 should be 3", () =>
{
var calculation = 1 + 2;
var isThree = calculation == 3;
return (isThree, $"1 + 2 should be 3 but actually was {calculation}");
});
Run(args); //Tell Tasty to execute the test cases
}
}
}
Cause it's a normal console application, we just can run it with the known dotnet commands you already know, so let's execute the project:
dotnet run
We should get an output similar to this:
👍 [00:00:00.0042] 1 + 2 should be 3
=================================================================================================
Summary: F0 | I0 | NR0 | S1 | T1
Time: [00:00:00.0000] | [00:00:00.0000] | [00:00:00.0000] | [00:00:00.0042] | [00:00:00.0042]
Outcome: Success
=================================================================================================
To name a few:
Feel free to send a pull request to add your repo or organisation to this list!
You need to have node v12 and dotnet sdk 3.1 installed on your local machine.
We use node only for linting commit messages and pushes so make sure to install the proper hooks by running:
npm install
Afterwards you are able to commit code either by hand using the commitizen rules or by running:
git cz
//OR
npm run c
You should be able to build the project by using the build scripts:
#Windows
build.bat
#Or for short
b.bat
#Or for powershell
./build.ps1
#Linux & MacOS
. build.sh
The project uses bullseye to list individual targets use build -l
.
This project uses dotnet format
to keep the code base consistent. If the build fails, you can use build format
to automatically format code against the rules defined.
By default when you commit the message is linted and before you push changes a default integration build is started. To bypass this behavior you can add --no-verify
to the git commit
or git push
commands.
We use Wyam to write the documentation. To serve up docs simply call b docs.serve
and open http://localhost:5080/
. All documentation is in the docs
directory.
Tasty is dual-licensed under the License Zero Prosperity Public License and the License Zero Private License. The Prosperity License limits commercial use to a thirty-day trial period, after which a license fee must be paid to obtain a Private License.