首页 > 解决方案 > 如何让 xunit 使用 xunit.gherkin.quick 在 Linux 上查找 dotnet 核心测试

问题描述

我正在尝试使用 dotnet core 和 xunit.gherkin.quick 进行一些 BDD 测试。(https://github.com/ttutisani/Xunit.Gherkin.Quick

我创建了一个可以在 Windows https://github.com/Richie5555/QuickTest上完全运行的项目

通过完全工作,我可以发出命令“dotnet test”,我得到一个通过测试,我可以发出命令“dotnet xunit”,我得到一个通过测试。(最后我需要运行 'dotnet xunit -xml results.xml' 以获得 xunit 测试报告。

但是,当我尝试在 Linux (centOS) 上运行它时,“dotnet test”按预期工作,但是“dotnet xunit”没有找到任何测试。

在谷歌上搜索了几天(并尝试了很多东西)我很难过!

请问谁能帮忙解决这个问题?

我的 .csproj 文件是:

    <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.gherkin.quick" Version="3.3.0" />
    <PackageReference Include="xunit.runner.console" Version="2.4.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
  </ItemGroup>

     <ItemGroup>
    <None Update="./FeatureFiles/*.feature">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

我的功能文件是:

Feature: FeatureOne

    Scenario: ScenarioOne
        When I add 1 plus 1
        Then the answer should be 2

我的 StepDefinition 文件是:

using Xunit;
using Xunit.Gherkin.Quick;

namespace QuickTest.StepDefinitions
{
    [FeatureFile("./FeatureFiles/FeatureOne.feature")]
    public sealed class FeatureOneSteps : Feature
    {
        private int _Answer = 0;

        [When(@"I add 1 plus 1")]
        public void IAdd1Plus1()
        {
            _Answer = 1 + 1;
        }

        [Then(@"the answer should be 2")]
        public void TheAnswerShouldBe2()
        {
            Assert.Equal(2, _Answer);
        }
    }
}

在 Windows 上运行“dotnet --info”(工作正常):

.NET Core SDK (reflecting any global.json):
 Version:   2.1.403
 Commit:    04e15494b6

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.403\

Host (useful for support):
  Version: 2.1.5
  Commit:  290303f510

.NET Core SDKs installed:
  2.1.403 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

在 Linux 上做同样的事情:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.403
 Commit:    04e15494b6

Runtime Environment:
 OS Name:     amzn
 OS Version:  2
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.403/

Host (useful for support):
  Version: 2.1.5
  Commit:  290303f510

.NET Core SDKs installed:
  2.1.403 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

如果需要更多信息来帮助我,请告诉我!:)

标签: linuxtesting.net-corexunit

解决方案


推荐阅读