Skip to content

Unable to access test execution dependent service 'Reqnroll.TestThreadContext' with the Reqnroll.Microsoft.Extensions.DependencyInjection plugin #561

@joey7755

Description

@joey7755

Reqnroll Version

2.4.0

Which test runner are you using?

MSTest

Test Runner Version Number

2.4.0

.NET Implementation

.NET 8.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

{
  "$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json",

    "bindingAssemblies": [
        {
            "assembly": "Credentials.UI.Integration.Tests"
        }
    ]
}

Issue Description

While converting specflow tests to Reqnroll, I came across this exception. The same has worked fine with specflow but somehow vausing triuble when migrated tests from specflow to reqnroll. Build worked fine. Issue while running scripts.

Error: Unable to access test execution dependent service 'Reqnroll.TestThreadContext' with the Reqnroll.Microsoft.Extensions.DependencyInjection plugin. This service is only available once test execution has been started and cannot be used in '[BeforeTestRun]' hook.

Any help would be much appreciated.

Below is the code written for hooks.cs

 [Binding]
    
        public sealed class Hooks
        
        {
         
        private static TestContext _textContext;
        
        public Hooks()
        
        {
                 
         }
        
             [BeforeTestRun]
             public static void BeforeTestRun(TestThreadContext threadContext, IConfiguration configuration) 
             {
                 _textContext = threadContext.TestThreadContainer.Resolve<TestContext>();
        
                 if (_textContext.Properties.Contains("Environment") &&
                     _textContext.Properties["Environment"].ToString() == "dev")
                 {
                     threadContext.Add("portal", configuration["portal:url"]);
                 }
                else
                {
                }
             }
           [AfterScenario]
            public void AfterScenario(BrowserDriver browserDriver)
             {
              browserDriver.Current.Close();
              browserDriver.Current.Quit();
             }

             }
           }

Steps to Reproduce

  • Build works fine
  • Issue when running the tests

Link to Repro Project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions