NUnit 3控制台运行程序无法断言该集合是否已订购

时间:2016-02-15 14:31:47

标签: c# travis-ci nunit-console nunit-3.0

我正在使用Travis CI运行CI构建。我通过nunit3-console.exe运行NUnit测试。我有几个测试试图断言收集了一个集合:

[Test]
public void FeatsAreSorted()
{
    var result = controller.Generate() as JsonResult;
    dynamic data = result.Data;
    Assert.That(data.character.Ability.Feats, Is.Ordered.By("Name"));
}

当我在Visual Studio中运行此测试时,测试通过正常。但是,当我在Travis CI中通过nunit3-console.exe运行测试时,出现以下错误:

1) Error : DNDGenSite.Tests.Unit.Controllers.CharacterControllerTests.GenerateSortsCharacterFeats
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : `NUnit.Framework.Assert.That<System.Linq.OrderedEnumerable<CharacterGen.Common.Abilities.Feats.Feat,string>>(System.Linq.OrderedEnumerable<CharacterGen.Common.Abilities.Feats.Feat,string>, NUnit.Framework.Constraints.IResolveConstraint)' is inaccessible due to its protection level

这是我的.travis.yml

language: csharp
solution: DNDGenSite.sln
install:
  - nuget restore DNDGenSite.sln
  - nuget install NUnit.Runners -OutputDirectory testrunner
  - nuget install Chutzpah -OutputDirectory testrunner
script:
  - xbuild DNDGenSite.sln /p:TargetFrameworkVersion="v4.5.1" /p:Configuration=Release
  - mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/bin/Release/DNDGenSite.Tests.dll
  - mono ./testrunner/Chutzpah.*/tools/chutzpah.console.exe ./Tests/Unit/Scripts

有什么想法吗?

UPDATE:如果我在git bash中运行测试,则所有内容都会在DebugRelease构建模式下正确传递。因此,Travis CI构建控制台运行环境的环境有所不同。

1 个答案:

答案 0 :(得分:0)

最后,我发现断言dynamic对象的顺序导致了Travis中的错误。如果相反,我验证它等于一个不同的对象并检查tat对象的属性,测试通过正常。