我正在尝试使用dotnet core和xunit.gherkin.quick进行一些BDD测试。 (https://github.com/ttutisani/Xunit.Gherkin.Quick)
我已经创建了一个可以在Windows https://github.com/Richie5555/QuickTest上完全运行的项目
通过完全工作,我可以发出命令“ dotnet测试”,并且获得通过测试,并且可以发出命令“ dotnet xunit”,并且得到通过测试。 (我最后需要运行'dotnet xunit -xml results.xml'以获得xunit测试报告。
但是,当我尝试在Linux(centOS)上运行此程序时,“ dotnet测试”按预期工作,但是“ 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
如果需要更多信息以帮助您,请告诉我! :)