# Test-drive: the simple testing framework

**URL:** <https://fortran-lang.discourse.group/t/test-drive-the-simple-testing-framework/1820>\
**Category:** Announcements\
**Created:** [September 11, 2021, 8:46am UTC](https://fortran-lang.discourse.group/t/test-drive-the-simple-testing-framework/1820 "2021-09-11T08:46:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [September 11, 2021, 8:46am UTC](https://fortran-lang.discourse.group/t/test-drive-the-simple-testing-framework/1820/1 "2021-09-11T08:46:59Z")

</div>

I just released the first official version of the _test-drive_ project, which offers a procedural approach for creating and organizing unit tests, without requiring external tools and only using standard Fortran. I developed this project originally for TOML Fortran and the Fortran package manager (fpm) as a light-weight and practical option to run our unit tests.

It turned out good enough to spin off a separate testing framework and we are now in the progress of adopting it for testing stdlib: [Add testing module to allow better structuring of test suites by awvwgk · Pull Request #494 · fortran-lang/stdlib · GitHub](https://github.com/fortran-lang/stdlib/pull/494).

Therefore, we decided to maintain it at the Fortran-lang GitHub organization from now on:

> **[GitHub - fortran-lang/test-drive: The simple testing framework](https://github.com/fortran-lang/test-drive)**
>
> The simple testing framework. Contribute to fortran-lang/test-drive development by creating an account on GitHub.

Support for meson, cmake and fpm is available with _test-drive_ and I already updated the [cmake template](https://github.com/fortran-lang/stdlib-cmake-example) to automatically make _test-drive_ available together with _stdlib_. Since it just a single file you could also just drop it in your project without any build system integration required.

_How does it work?_

A test defined for this framework will have access to a derived type for error handling and a overloaded procedure called `check` to create the actual test conditions.

```fortran
subroutine test_something(error)
  type(error_type), allocatable, intent(out) :: error
  ! ... do calculation
  call check(error, actual, expected)
end subroutine test_something

```

The `error_type` is not really special or fancy, because it contains basically only an error message when allocated, the only special thing is that it uses a _final_ procedure to enforce no test condition can fail unnoticed.

There is some boilerplate to collect and organize the unit tests in test suites and allow selection of individual tests or suites via command line arguments as well, which is mainly based on small derived types with procedure pointers. I found Fortran’s way of handling procedure pointers provides a very powerful and expressive way to build complex but well-defined workflows without needing object-oriented programming patterns.

Feedback is of course very welcome. Feel free to leave a comment here, open an issue at the repository or send a patch.
