特征文件似乎无法识别 Specflow 步骤文件

Specflow step file doesn't appear to be recognised by feature file

我创建了一个 Specflow 项目,它有一个特征文件,EBIntegrationTest.feature :

Feature: EBIntegrationTest for MF
    Initial test feature

@mytag
Scenario: Subscribe to Market Data EU Topic and write to SQL DB
    Given MD messages are streaming to MF application
    When MF enriches template 304
    Then the enriched messages are then written to an SQL DB server

然后我在我的 Steps 文件夹中添加了一个步骤文件:

using System;
using System.Collections.Generic;
using System.Text;

namespace eb_test_tool.Steps
{
    class EBIntegrationTest
    {
        [Given(@"MD messages are streaming to MF application")]
        public void GivenMDMessagesAreStreamingToMFApplication()
        {
            var processInfo = new ProcessStartInfo("C:\ProgramData\CME\Java_SymLinks\JDK8_x64\jre\bin\java.exe",
                                                   "java -jar .\Jar\Injector\MD-Injector-1.0.jar My.TOPIC")
            {
                CreateNoWindow = true,
                UseShellExecute = false
            };
            Process proc;

            if ((proc = Process.Start(processInfo)) == null)
            {
                throw new InvalidOperationException("Message injector failed to run");
            }

            proc.WaitForExit();
            int exitCode = proc.ExitCode;
            proc.Close();
        }
        
        [When(@"MF enriches template (.*)")]
        public void WhenMFEnrichesTemplate(int p0)
        {
            ScenarioContext.Current.Pending();
        }
        
        [Then(@"The enriched messages are then written to an SQL DB server")]
        public void ThenTheEnrichedMessagesAreThenWrittenToAnSQLDBServer()
        {
            ScenarioContext.Current.Pending();
        }

    }
}

当我 运行 dotnet test 它被跳过并显示此警报:

我是不是做错了什么,或者我应该以某种方式从功能文件中引用我的步骤文件?

您需要将 [Binding] 属性添加到您的 EBIntegrationTest class 并使其成为 public.

[Binding]
public class EBIntegrationTest
{
//...
}

我在 .csproj 文件中注意到了这一点。当我删除它时,问题就解决了。

<ItemGroup>
    <Compile Remove="Steps\EBSIntegrationTestStepDefinitions.cs" />
</ItemGroup>