C#-Mono和Specflow-名称空间“ NUnit.Framework”中不存在“ TestCaseAttribute”
作者:互联网
我目前正在尝试在OSX上运行一些Specflow测试,但是在尝试运行Unit案例时遇到了一些构建错误.为了简要说明一下,我正在为Hiptest进行测试导出,而我绝对不是C#专家,所以我可能在做愚蠢的事情.
所以这是我要执行的步骤:
nuget install SpecFlow
mono SpecFlow.1.9.0/tools/specflow.exe generateall specflow_samples.csproj
规格flow_samples的内容如下:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="features/Scenarios.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Scenarios.feature.cs</LastGenOutput>
</None>
<None Include="features/Error_messages.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Error_messages.feature.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
那部分工作正常,我正在按预期获取.feature.cs文件.现在,当我尝试在运行测试之前构建dll时,就会出现问题.
mcs /target:library /out:hiptest.publisher.samples.dll ../csharp/class/CoffeeMachine.cs features/Actionwords.cs features/Error_messages.feature.cs features/Scenarios.feature.cs -reference:nunit.framework.dll -r:SpecFlow.1.9.0/tools/TechTalk.SpecFlow.dll
这是输出:
features/Scenarios.feature(41,26): error CS0234: The type or namespace name `TestCaseAttribute' does not exist in the namespace `NUnit.Framework'. Are you missing an assembly reference?
features/Scenarios.feature(42,26): error CS0234: The type or namespace name `TestCaseAttribute' does not exist in the namespace `NUnit.Framework'. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
我认为添加对unit.framework.dll的引用就足够了,但显然还不够.我在这里错过明显的东西吗?
一些可能有用的信息.我正在使用与Mono捆绑在一起的Unit(显然是2.4.8,基于unit-console的输出)和Mono版本4.2.0.
如果有帮助,我将其粘贴在Specflow生成的文件之一下面.
提前致谢,
文森特
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.9.0.77
// SpecFlow Generator Version:1.9.0.0
// Runtime Version:4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace SpecFlow.GeneratedTests
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Scenarios")]
public partial class ScenariosFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "Scenarios.feature"
#line hidden
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void FeatureSetup()
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Scenarios", "", ProgrammingLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[NUnit.Framework.TestFixtureTearDownAttribute()]
public virtual void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
[NUnit.Framework.SetUpAttribute()]
public virtual void TestInitialize()
{
}
[NUnit.Framework.TearDownAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
public virtual void ScenarioCleanup()
{
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Simple use")]
[NUnit.Framework.TestCaseAttribute("en", "Ready", "uid:be213f3d-8bd2-4c37-8ed2-3a494fd92e87", null)]
[NUnit.Framework.TestCaseAttribute("fr", "Pret", "uid:98096345-3522-4858-b55c-e02196b18482", null)]
public virtual void SimpleUse(string lang, string ready_Message, string hiptest_Uid, string[] exampleTags)
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Simple use", exampleTags);
#line 4
this.ScenarioSetup(scenarioInfo);
#line 5
testRunner.And("Assert displayed message \"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 6
testRunner.And(string.Format("Start the coffee machine \"{0}\"", lang), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 7
testRunner.And(string.Format("Assert displayed message \"{0}\"", ready_Message), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 8
testRunner.And("Take a coffee", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 9
testRunner.And("Assert coffee served", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 10
testRunner.And("Shutdown coffee machine", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 11
testRunner.And("Assert displayed message \"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line hidden
this.ScenarioCleanup();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Full grounds does not block coffee (uid:1d0d17c3-355e-4a6e-b293-ecaa533b21ef)")]
public virtual void FullGroundsDoesNotBlockCoffeeUid1D0D17C3_355E_4A6E_B293_Ecaa533B21Ef()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Full grounds does not block coffee (uid:1d0d17c3-355e-4a6e-b293-ecaa533b21ef)", ((string[])(null)));
#line 18
this.ScenarioSetup(scenarioInfo);
#line 19
testRunner.And("Start the coffee machine \"en\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 20
testRunner.And("Take coffees \"29\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 21
testRunner.And("Assert displayed message \"Ready\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 22
testRunner.And("Take a coffee", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 23
testRunner.And("Assert coffee served", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 24
testRunner.And("Assert displayed message \"Empty grounds\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 25
testRunner.And("Fill water tank", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 26
testRunner.And("Fill beans", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 27
testRunner.And("Take coffees \"20\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 28
testRunner.And("Assert coffee served", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line 29
testRunner.And("Assert displayed message \"Empty grounds\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "* ");
#line hidden
this.ScenarioCleanup();
}
}
}
#pragma warning restore
#endregion
解决方法:
您需要引用NUnit.Framework 2.5或更高版本.在NUnit 2.5中添加了TestCaseAttribute.
NUnit.Framework版本2.4.8是当前Mono附带的版本.它没有TestCaseAttribute.
标签:command-line,mono,specflow,c 来源: https://codeday.me/bug/20191119/2035983.html