1
votes

I am setting up NUnit C# tests using SpecFlow, but the ones declared in my SpecFlowFeature don't seem to be picked up by the Text Explorer. When trying to manually run the scenario (by right-clicking on them) I get the following error:

 "Cannot access a disposed object. Object name: 'GherkinLanguageService'"

...which doesn't ring any bell at all. Anyone has any suggestion on how to allow them to run?

The Feature Code is as follows:

Feature: SpecFlowFeature
    As a user
    I would like to go to the what we do page
    In order to see what we do information

@UI
Scenario: What we do Browsing
    Given I have the home page open
    When I select what we do from the menu
    Then I see the what we do information

@UI
Scenario: Add an Asset to a Client page
    Given I have the home page open
    When I go to a client page
    And I click the Add Download button
    And I fill in the form
    And I choose a file to upload
    And I submit the form
    Then I see the newly-submitted file

And the Steps definitions are all automatically generated.

EDIT: List of installed NuGet packages in my Test Project:

  • Microsoft.Net.Compilers 1.1.0-rc1
  • NUnit 3.4.0
  • NUnitTestAdapter 2.0.0
  • Selenium.WebDriver 2.53.0
  • SpecFlow 2.1.0
  • SpecFlow.NUnit 2.1.0
  • SpecFlow.NUnit.Runners 2.1.0
2
Can you add your code?Gilad Green
Added SpecFlowFeature. Anything else you need? The rest of the code is automatically generated from the feature, and no build errors are present.Emanuele Ciriachi
Is there any code in those functions? or is it still just the default empty generated ones?Gilad Green
Yes there is code, but I am getting this error message before the test runs - I even put log messages in the first method, it never get to run.Emanuele Ciriachi
@EmanueleCiriachi: Please specify your SpecFlow version and the list of installed NuGet packages in the test project.Andreas Willich

2 Answers

2
votes

The problem was a subtle dependency issue. The previous version used NUnit 2.x, while my current version uses NUnit 3.x; now in order to use NUnit I need a NuGet package called "NUnit Test Adapter", but upgrading it is not enough: apparently for NUnit 3+ there is a different package called "NUnit 3 Test Adapter" which is not just an upgraded version of the previous one - but a different one altogether.

Installing NUnit 3 Test Adapter solved my problem.

1
votes

Have a look at the code in this repo https://github.com/SabotageAndi/SpecFlow.Example.AllTestRunners and compare it with your project.

It contains a SpecFlow project for NUnit 2 and NUnit 3.2.1.
There the NUnit Tests are visible in the Visual Studio Test Explorer.

First I would try a downgrade to 3.2.1 of NUnit. Perhaps there is some problem in connection with the NUnitTestAdapter.