0
votes

I was wondering if anybody could help with an issue I have come across, I have recently added to my test framework the sharing of a value using feature content

This has been placed in the [BeforeScenario] trigger

FeatureContext.Current.Add("CreatedUser", createdUser);

I then clean this up in the [AfterScenario] with

FeatureContext.Current.Remove("CreatedUser");

Since adding this I am unable to run more then 1 test, if I run the tests individually (1 by 1) then they execute with no issue.

If I select a few tests to run from visual studio, the first one runs with no issue and the next test will always fail with the following error.

Message: System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary. TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

I added the remove line as i thought the feature context was being carried from test to test and causing an issue but with or without the removal i am getting this error.

Any help is appreciated

1
Did you debug your case? Select 2 tests, set a breakpoint in [AfterScenario] and [BeforeScenario] and investigate the content of FeatureContext.Current. Also have a look at the complete callstack where the exception is thrown. It would be fine if you update your question with a minimal code example. - Jeroen Heier
Yesi did debug this and found it was being thrown before hitting my code, which is why I did not place a coding example as I did not think this was going to be useful. - Brian Mitchell

1 Answers

0
votes

I eventually managed to fix this issue by removing the Allure NuGet packages.

I had previously installed

  • Specflow.Allure
  • Allure.Commons

This package was causing the issue, I am not sure of the reason but after removing this error stopped occurring.