reqnroll / Reqnroll

Open-source Cucumber-style BDD test automation framework for .NET.
https://reqnroll.net
BSD 3-Clause "New" or "Revised" License
302 stars 33 forks source link

Dispose method is not called on objects registered for the TestThread container #123

Closed gasparnagy closed 1 month ago

gasparnagy commented 1 month ago

Reqnroll Version

1.0.1

Which test runner are you using?

MSTest

Test Runner Version Number

n/a

.NET Implementation

.NET 8.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

No response

Issue Description

If an type is registered to the test thread container (via TestThreadContext.TestThreadContainer), that implements IDisposable, and the container creates an instance (someone resolves it) it is expected that the Dispose method will be called latest before the test execution is finished.

But this will not happen, because Reqnroll does not dispose the test runners at the test-run end (TestRunnerManager.FireTestRunEndAsync).

Steps to Reproduce

See repo/workaround at https://github.com/reqnroll/Sample-ReqOverflow/blob/main/ReqOverflow.Specs.WebUI/Support/BrowserFactory.cs#L61

Link to Repro Project

https://github.com/reqnroll/Sample-ReqOverflow/blob/main/ReqOverflow.Specs.WebUI

Code-Grump commented 1 month ago

Is it expected? The behaviour with IDisposable has always been a bit fuzzy, but the rules I understand is that if you create the object, you are responsible for its lifecycle and calling Dispose() when done. If the container creates the object, it should be responsible for its lifecycle. If the container was given an instance of the object, it should not dispose the object unless it was given an explicit instruction to take ownership of the lifecycle.

gasparnagy commented 1 month ago

@Code-Grump Yes, thx for the clarification. I was not clear enough. The problem is that if the container creates the object (so you just have a type registration) the Dispose will not be called. I'll change the description to make this clear.