Emanuele Ciriachi
Emanuele Ciriachi

Reputation: 2264

Error when attempting to run SpecFlow NUnit test: "Cannot access a disposed object. Object name: 'GherkinLanguageService'"

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:

Upvotes: 1

Views: 1703

Answers (2)

Emanuele Ciriachi
Emanuele Ciriachi

Reputation: 2264

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.

Upvotes: 2

Andreas Willich
Andreas Willich

Reputation: 5825

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.

Upvotes: 1

Related Questions