Mono和Specflow-`TestCaseAttribute';在命名空间`NUnit.Framework&#

本文关键字:命名空间 NUnit Framework Specflow- TestCaseAttribute Mono | 更新日期: 2023-09-27 18:22:31

我目前正试图在OSX上运行一些Specflow测试,但在尝试运行单元案例时遇到了一些构建错误。简单地说,我正在为Hiptest开发测试导出器,我绝对不是C#专家,所以我可能在做一些愚蠢的事情。

下面是我要遵循的步骤:

nuget install SpecFlow
mono SpecFlow.1.9.0/tools/specflow.exe generateall specflow_samples.csproj

规范流程_样本的内容如下:

<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,基于单元控制台的输出)和Mono 4.2.0版本。我粘贴在Specflow生成的一个文件下面,以防有帮助。

提前感谢,Vincent

// ------------------------------------------------------------------------------
    //  <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

Mono和Specflow-`TestCaseAttribute';在命名空间`NUnit.Framework&#

您需要参考NUnit.Framework 2.5或更高版本。在NUnit 2.5中添加了TestCaseAttribute。

NUnit.Framework 2.4.8版本是目前Mono附带的版本。它没有TestCaseAttribute。