Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With NUnit 4.x, "Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode" #379

Open
SeanKilleen opened this issue Jan 2, 2025 · 5 comments · May be fixed by #388
Labels
bug Something isn't working

Comments

@SeanKilleen
Copy link
Contributor

SeanKilleen commented Jan 2, 2025

Reqnroll Version

2.2.1

Which test runner are you using?

NUnit

Test Runner Version Number

4.3.2

.NET Implementation

.NET 9.0

Test Execution Method

Other – PLEASE SPECIFY

Content of reqnroll.json configuration file

No file in use to my knowledge.

Issue Description

Firstly, I absolutely love the way you're stepping in to support the community with this tool and I look forward to promoting and supporting it however I can.


This seems similar to #320 except I'm still experiencing the issue after installing Reqnroll v2.2.1.

Background

  • I'm in the process of replacing SpecFlow with Reqnroll (have I mentioned that I absolutely love you for this?)
  • My current project uses NUnit 4.3.2 along with TestContainers for some unrelated standard unit tests we have that test IronPDF.
  • I'm removing SpecFlow.NUnit and SpecFlow.Tools.MSBuild.Generation and replacing them with the latest (2.2.1) of Reqnroll.NUnit and Reqnroll.Tools.MsBuild.Generation.

Problem

The tests that are unrelated to Reqnroll have begun to fail.

The output of these tests in that branch is now:

OneTimeSetUp: System.InvalidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.

Steps to Reproduce

See repro project below which includes a very small reproduction project.

Link to Repro Project

https://github.com/sct-software/Reqnroll-379-reproduction

@SeanKilleen SeanKilleen added the bug Something isn't working label Jan 2, 2025
@SeanKilleen
Copy link
Contributor Author

While I work on the smaller reproduction, some information that may help --

It looks like in NUnit.AssemblyHooks.template.cs, the FixtureLifeCycle is set to InstancePerTestCase.

I'm not sure if this is intended, but it conflicts with the NUnit default, which according to the docs is SingleInstance.

Because this assembly-level attribute is set, I think my tests are picking up the non-default behavior and NUnit is therefore expecting them to adhere to the static constraint.

@SeanKilleen
Copy link
Contributor Author

SeanKilleen commented Jan 2, 2025

You can find a basic reproduction at https://github.com/sct-software/Reqnroll-379-reproduction

There are two tags -- the commit prior to the issue being introduced, and then adding Reqnroll.NUnit which introduces the issue. The current commit on the main branch has the issue reproduced.

@SeanKilleen
Copy link
Contributor Author

An quick workaround for this is setting [FixtureLifeCycle(LifeCycle.SingleInstance)] on our non-Reqnroll test class -- this resolved the issue.

So I'd suggest the outcome of this issue could be:

I'm happy to do a PR for either of those.

@obligaron
Copy link
Contributor

Thanks for the good analysis and reproduction 🙂 .

This change was introduced when we supported parallel execution at the scenario/method level (see #277).

We could fix this by adding the FixtureLifeCycle to each generated class instead of doing it globally.

@SeanKilleen
Copy link
Contributor Author

Sounds good, I'll do the PR for it, today if I can. Not mad if anyone beats me to it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants