# Parametrized tests

**URL:** <https://internals.rust-lang.org/t/parametrized-tests/15273>\
**Category:** tools and infrastructure\
**Created:** [September 3, 2021, 12:17pm UTC](https://internals.rust-lang.org/t/parametrized-tests/15273 "2021-09-03T12:17:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruza-net](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ruza-net/32/7948_2.png) [@ruza-net](https://internals.rust-lang.org/u/ruza-net)\
**Post date:** [September 3, 2021, 12:17pm UTC](https://internals.rust-lang.org/t/parametrized-tests/15273/1 "2021-09-03T12:17:08Z")

</div>

This is a survey/question topic.

Recently, I'm finding myself in a situation where I want to test an interface (e.g. a trait). The way I do it right now is to setup a dummy/mock object which implements it, and then use it in the test suite (possibly wrapping it in `Box<dyn TheTrait>`).

However, what if I wanted to create a separate crate with a different implementor of the tested trait? I would need to transfer the test suite manually, which isn't ergonomic. I want to write the tests for a generic type implementing `TheTrait` and then instantiate the tests for a particular implementation.

The hypothetical ways of doing this that come to my mind are:

1. generic modules (the module arguments get expanded into local `type` aliases)
2. allowing testing `trait`s (the test cases are declared as the trait's associated functions and are run on a particular `impl`)

What do you think about this, and which ways would you test an interface?

---

<div class="post-metadata">

**Author:** ![jjpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jjpe/32/9779_2.png) [@jjpe](https://internals.rust-lang.org/u/jjpe)\
**Post date:** [September 3, 2021, 1:08pm UTC](https://internals.rust-lang.org/t/parametrized-tests/15273/2 "2021-09-03T13:08:01Z")

</div>

> [@ruza-net](#):
>
> What do you think about this, and which ways would you test an interface?

Personally at this moment, I'd write a function or macro that takes as parameters whatever differs between those tests, put that in a separate crate, and just use it where appropriate as a dev-dependency.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [December 2, 2021, 1:08pm UTC](https://internals.rust-lang.org/t/parametrized-tests/15273/3 "2021-12-02T13:08:09Z")

</div>

Closed on December 2, 2021, 1:08pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
