使用 TestDriven.Net 时出现 Specflow 错误 - 无法找到类型
我是第一次尝试 Specflow,并创建了一个引用 TechTalk.SpecFlow 以及 nunit.framework 的 VS2010 项目。我添加了一个示例功能文件:
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
@mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
当我执行测试(使用 TestDriven.Net)时,出现以下错误:
Test 'T:SpecFlowFeature1' failed: Couldn't find type with name 'SpecFlowFeature1'
System.Exception: Couldn't find type with name 'SpecFlowFeature1'
at MutantDesign.Xml.Documentation.MemberInfoUtilities.FindMemberInfo(Assembly assembly, String cref)
at TestDriven.TestRunner.AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)
at TestDriven.TestRunner.ThreadTestRunner.Runner.Run()
有人知道我缺少什么吗?
I'm trying out Specflow for the first time, and have created a VS2010 project with a reference to TechTalk.SpecFlow, as well as nunit.framework. I've added a sample Feature file:
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
@mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
When I execuyte the test (using TestDriven.Net), I get the following error:
Test 'T:SpecFlowFeature1' failed: Couldn't find type with name 'SpecFlowFeature1'
System.Exception: Couldn't find type with name 'SpecFlowFeature1'
at MutantDesign.Xml.Documentation.MemberInfoUtilities.FindMemberInfo(Assembly assembly, String cref)
at TestDriven.TestRunner.AdaptorTestRunner.Run(ITestListener testListener, ITraceListener traceListener, String assemblyPath, String testPath)
at TestDriven.TestRunner.ThreadTestRunner.Runner.Run()
Anyone know what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上可以追溯到我如何运行测试。右键单击“.feature”文件(或该文件中的任何位置)并选择“运行测试”会导致错误。右键单击底层的“.feature.cs”文件并选择“运行测试”,正确执行。看起来 TestDriven.Net 无法“理解”“*.feature”文件。
Actually traced this down to how I was running the test. Right clicking the ".feature" file (or anywhere within that file) and selecting "Run Tests" resulted in the error. Right clicking the underlying ".feature.cs" file and selecting "Run Tests" executed correctly. Looks like TestDriven.Net wasn't able to "understand" the "*.feature" file.
我通常会在引用文件夹中启动“无法找到类型...”错误,并确保我引用的库被正确引用,并且引用的版本没有过时。
另外,请确保您的 SpecFlowFeature1 类没有被错误地声明为私有。 Visual Studio 将新类(默认情况下)创建为私有类,如果您未将类指定为公共类,则它将保持私有状态,并且对外部项目不“可见”。
I typically start "Couldn't find type..." errors in my references folder and make sure that the library that I'm referencing is being referenced correctly and that the version that's being referenced isn't outdated.
Also, make sure that your SpecFlowFeature1 class isn't mistakenly declared as private. Visual Studio creates new classes (by default) as private and if you don't specify a class as public, it will remain private and not "visible" to outside projects.