Mono 和 Specflow - 命名空间“NUnit.Framework”中不存在“TestCaseAttribute”

Mono and Specflow - `TestCaseAttribute' does not exist in the namespace `NUnit.Framework'

我目前正尝试 运行 在 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。