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

TearDown : System.InvalidOperationException #320

Closed
russog opened this issue Nov 8, 2024 · 17 comments · Fixed by #323
Closed

TearDown : System.InvalidOperationException #320

russog opened this issue Nov 8, 2024 · 17 comments · Fixed by #323
Labels
bug Something isn't working

Comments

@russog
Copy link

russog commented Nov 8, 2024

Reqnroll Version

2.2.0

Which test runner are you using?

NUnit

Test Runner Version Number

latest

.NET Implementation

.NET 8.0

Test Execution Method

Command line – PLEASE SPECIFY THE FULL COMMAND LINE

Content of reqnroll.json configuration file

dotnet test

Issue Description

TearDown : System.InvalidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.
--TearDown
at NUnit.Framework.Internal.Execution.StaticMethodValidator.Validate(MethodInfo method)
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunTearDown(TestExecutionContext context)

Steps to Reproduce

dotnet test or simply run the test runner

Link to Repro Project

No response

@russog russog added the bug Something isn't working label Nov 8, 2024
@konarx
Copy link

konarx commented Nov 8, 2024

+1
I started getting this error out of nowhere, and then I remembered, "Oh, I upgraded the Nuget yesterday." 😋

@D0nGiovanni
Copy link

I just experienced the same problem. The problem lies in the incompatibility with NUnit 4.0.0+. Tests don't break up until NUnit 3.14.

@gasparnagy
Copy link
Contributor

@russog @D0nGiovanni @konarx Stupid question, but I guess you don't have any [OneTimeSetUp] or [OneTimeTearDown] that you have defined yourself, right?

@gasparnagy
Copy link
Contributor

Also could you please tell the exact version number of NUnit you use and get the error?

@russog
Copy link
Author

russog commented Nov 8, 2024

@gasparnagy yes, but in a separate project not the one that gives me trouble,

@russog
Copy link
Author

russog commented Nov 8, 2024

NUnit: 4.2.2
NUnit.Analyzers: 4.3.0
NUnit3TestAdapter: 4.6.0

@gasparnagy
Copy link
Contributor

yes, but in a separate project not the one that gives me trouble,

@russog do you think this have any relation to the issue (are the projects refer each-other)? Do you still get the error if you temporarily comment out those [OneTimeSetUp]/[OneTimeTearDown] methods on the other project?

@russog
Copy link
Author

russog commented Nov 8, 2024

nope. just to be sure I run from the command line dotnet test the other one is not referenced in it.
from the command line I get a warning (the same message I posted in the subject) with the testrunner the test pass but it gives a massive red cross on the test project

@russog
Copy link
Author

russog commented Nov 8, 2024

btw you guys are doing an amazing job ;)

@gasparnagy
Copy link
Contributor

I am trying it with the refs as

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
    <PackageReference Include="Reqnroll.NUnit" Version="2.2.0" />
    <PackageReference Include="nunit" Version="4.2.2" />
    <PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
  </ItemGroup>

But works for me.

Maybe any special NUnit assembly-level attribute?

Also one more:
In the obj/Debug/net8.0 folder of your project, there should be a file called 'NUnit.AssemblyHooks.cs'. Could you please paste the content?

@konarx
Copy link

konarx commented Nov 8, 2024

@konarx Stupid question, but I guess you don't have any [OneTimeSetUp] or [OneTimeTearDown] that you have defined yourself, right?

@gasparnagy no, but I have a [Binding]TestRunLevelHooks.cs class with one [BeforeTestRun] and one [AfterTestRun] methods.
My NuGets:

<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.Playwright" Version="1.48.0" />
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="ReportPortal.Extensions.SourceBack" Version="2.1.0" />
<PackageReference Include="ReportPortal.Reqnroll" Version="1.1.0" />
<PackageReference Include="Reqnroll.NUnit" Version="2.2.0" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="nunit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="JunitXml.TestLogger" Version="4.1.0" />

@D0nGiovanni
Copy link

@gasparnagy

you don't have any [OneTimeSetUp] or [OneTimeTearDown] that you have defined yourself, right?

No, I specifically checked my all my files. I found the culprit in the generated *.feature.cs file. The OneTimeTearDownAttribute annotated method is a virtual one, whereas the OneTimeSetup method is static, as it should be.

Also could you please tell the exact version number of NUnit you use and get the error?

NUnit: 4.0.0+
NUnit.Analyzers: 4.1.0
NUnit3TestAdapter: 4.1.0

@D0nGiovanni
Copy link

ReqnrollMinimalRepro.zip
This is the repro that fails.

@gasparnagy
Copy link
Contributor

This is the repro that fails.

@D0nGiovanni Strange. I do see the warning with your repo when using dotnet test, but from VS it just works

image

I have VS 17.11.4

@gasparnagy
Copy link
Contributor

I found the problem. Fix is on the way.

gasparnagy added a commit that referenced this issue Nov 8, 2024
…alidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.` (#320)
gasparnagy added a commit that referenced this issue Nov 8, 2024
…alidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.` (#323)

* Fix: NUnit projects fail or provide warning as `TearDown : System.InvalidOperationException : Only static OneTimeSetUp and OneTimeTearDown are allowed for InstancePerTestCase mode.` (#320)

* Add tests
@gasparnagy
Copy link
Contributor

please update to 2.2.1

@russog
Copy link
Author

russog commented Nov 8, 2024

@gasparnagy it works like a charm you definitely rock!

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
4 participants