试图运行SpecFlow NUnit测试时出错:"无法访问已处置的对象.对象名称:'GherkinLa
本文关键字:对象 GherkinLa 访问 出错 测试 SpecFlow 运行 quot NUnit | 更新日期: 2023-09-27 17:52:11
我正在使用SpecFlow设置NUnit c#测试,但是在我的SpecFlowFeature中声明的那些似乎没有被文本资源管理器拾取。当尝试手动运行场景时(通过右键单击它们),我得到以下错误:
"Cannot access a disposed object. Object name: 'GherkinLanguageService'"
…这听起来一点都不像。有人对如何让它们运行有什么建议吗?
特征码如下:
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
步骤定义都是自动生成的。
编辑:在我的测试项目中安装的NuGet包列表:
- Microsoft.Net。编译器1.1.0-rc1
- NUnit 3.4.0
- NUnitTestAdapter 2.0.0
- 硒。WebDriver 2.53.0
- SpecFlow 2.1.0的
- SpecFlow。NUnit 2.1.0
- SpecFlow.NUnit。跑步者2.1.0的
问题是一个微妙的依赖问题。以前的版本使用NUnit 2。x,而我当前的版本使用NUnit 3.x;现在为了使用NUnit,我需要一个名为"NUnit测试适配器"的NuGet包,但是升级它是不够的:显然对于NUnit 3+有一个不同的名为"NUnit 3测试适配器"的包,它不仅仅是前一个的升级版本,而是一个完全不同的版本。
安装NUnit 3测试适配器解决了我的问题
请查看此repo https://github.com/SabotageAndi/SpecFlow.Example.AllTestRunners中的代码,并将其与您的项目进行比较。
包含了NUnit 2和NUnit 3.2.1的SpecFlow项目。
在Visual Studio测试资源管理器中可以看到NUnit测试。
首先我会尝试降级到3.2.1的NUnit。可能是NUnitTestAdapter有问题