简体   繁体   English

将XUnit与Service Fabric一起使用

[英]Using XUnit with Service Fabric

I created a new Service Fabric application using the Stateless Service template. 我使用无状态服务模板创建了一个新的Service Fabric应用程序。 I added a simple class so I can write a unit test for it: 我添加了一个简单的类,所以我可以为它编写一个单元测试:

public class FakeClass
{
    public void DoStuff()
    {
        FabricClient client = new FabricClient();
    }
} 

I create a new class library for unit tests and reference the xUnit and xUnit runner nuget packages. 我为单元测试创​​建了一个新的类库,并引用了xUnit和xUnit runner nuget包。 When I try and run the unit tests I get the following error: 当我尝试运行单元测试时,我收到以下错误:

Result Message: System.BadImageFormatException : Could not load file or assembly 'XUnitExample.WebService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 结果消息:System.BadImageFormatException:无法加载文件或程序集“XUnitExample.WebService,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null”或其依赖项之一。 An attempt was made to load a program with an incorrect format. 尝试加载格式不正确的程序。

How can I get xUnit working with Service Fabric so I can write unit tests? 如何让xUnit与Service Fabric一起使用,以便我可以编写单元测试?

The issue apparently has to do with the default setting when creating new projects. 在创建新项目时,问题显然与默认设置有关。 When you create a new project it uses Any CPU as the default architecture and Service Fabric requires x64. 创建新项目时,它使用Any CPU作为默认体系结构,Service Fabric需要x64。

I had to go into the Project Build properties and change it use x64 as the target platform. 我不得不进入Project Build属性并使用x64作为目标平台进行更改。 After doing that my unit tests didn't show up in the Test Explorer so I had to change the following setting: 在执行此操作后,我的单元测试未显示在测试资源管理器中,因此我不得不更改以下设置:

Test -> Test Settings -> Default Processor Architecture -> x64 测试 - >测试设置 - >默认处理器架构 - > x64

This issue has nothing to do with service fabric. 此问题与服务结构无关。 Can you try reinstalling the xunit package? 你能尝试重新安装xunit包吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM