Skip to content

Add a template for a group of methods from one module#335

Open
bugRanger wants to merge 5 commits into
la10736:masterfrom
bugRanger:feature/module-template
Open

Add a template for a group of methods from one module#335
bugRanger wants to merge 5 commits into
la10736:masterfrom
bugRanger:feature/module-template

Conversation

@bugRanger
Copy link
Copy Markdown
Contributor

I'd like to share a solution to the problem of writing identical tests.

My project uses multiple implementations of the same trait. All tests have the same logic for verifying the behavior of the trait implementation; the only difference is in the #[fixture] section, where the implementation under test is selected.

The solution I propose is similar to #[template], except that we create a template for the entire module and, in this module, mark the methods that should be excluded from the template. The excluded methods are expected to be implemented with the necessary modifications wherever the template is used.

@la10736
Copy link
Copy Markdown
Owner

la10736 commented Mar 12, 2026

It's a way to implement what we called contract tests ... now this name is used for something different but the idea is "I would test the trait contract against different implementation".

Lot of years ago it was possible in rust import the same module file from different source code and I used this "wrong behaviour" to load different fixture from the same test file.

Anyway, I love this idea.

I have to fix the CI... I guess 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants