我目前正在尝试在OSX上运行一些Specflow测试但是在尝试运行Unit案例时我遇到了一些构建错误。为了简要介绍一下,我正在为Hiptest的测试导出器工作,而且我绝对不是C#专家,所以我可能会做蠢事。
以下是我所遵循的步骤:
nuget install SpecFlow
mono SpecFlow.1.9.0/tools/specflow.exe generateall specflow_samples.csproj
spec 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
答案 0 :(得分:3)
您需要参考NUnit.Framework版本2.5或更高版本。 TestCaseAttribute已添加到NUnit 2.5。
NUnit.Framework版本2.4.8是目前Mono附带的版本。这没有TestCaseAttribute。