About
Writing unit tests is easy with Dlang. Unfortunately when you have a big collection of unit tests, it get’s hard to maintain and debug them. In order to avoid these problems, you can use this flexible test runner for D programing language.
Motivation
There are many test runners for DLang and there are a few of them that have a lot of useful features that helps you to be more productive. Sometimes you need to use a custom feature that is not embedded with those libraries. Maybe it’s about a custom test report, a new discovery mode or an integration with a third party app like an IDE or Jenkins. In each of these cases you need to dig in a project that is not maintained or you need features that does not match the creators view about this subject.
In order to be able to extend your test runs without depending on other people, I propose a simple idea, inspired from well known projects like TestNg, NUnit and mocha, that exposes a simple interface that allows you to add what you want, when you want.
How it works
Trial is a dub package. Add it to the unittest configuration of your project and run dub test: it replaces the
default D test runner, discovers your unittest blocks and Spec suites, runs them and reports the results. There is
no separate executable to install.
"configurations": [
{ "name": "library" },
{ "name": "unittest", "dependencies": { "trial": "~>1.0.1" } }
]
Arguments after -- go to trial. For example dub test -- -t "=parses an empty list" runs exactly that test, and
dub test -- -r spec,xunit picks the reporters. The getting started guide walks through a
first project, and Command line lists every flag.
Features
This library intends to provide a rich set of features that helps you to customize your test runs:
- Getting started
- Command line
- Test discoveries
- Executors
- Reporters
- Steps
- Attributes
- Attachments
- Extending
Configurable
A trial.json file in the project folder sets the reporters, the executor, the thread count and where the reports are
written. It is optional, all its keys are optional, and the command line flags override it. See
Settings precedence.
Hacking
Please have a look at trial.interfaces.
To work on trial itself, clone the repository and run dub test. The library tests itself with its own runner.
Fluent Asserts
Since DLang does not have a rich assert library, you can use Fluent Asserts, a library that improves your experience of writing tests.