我创建了一个Service Fabric应用程序,并在解决方案中添加了一个MSTest项目来测试服务中的方法。
为此,我在MSTest项目中添加了对HelloWorldAPI.dll
的服务项目引用。
在此之后,我在Visual Studio Team Services(VSO)中创建了一个自动构建定义,并且我尝试通过此构建执行Visual Studio测试用例。但是,我收到以下错误:
> Starting task: Test Assemblies **\*test*.dll;-:**\obj\**
******************************************************************************
Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.104.1\tasks\VSTest\1.0.50\VSTest.ps1
Working folder: C:\a\1
Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\a\1\s\POC\ServiceFabric\HelloWorld\UnitTestProject1\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll" "C:\a\1\s\POC\ServiceFabric\HelloWorld\UnitTestProject1\bin\Debug\UnitTestProject1.dll" /logger:trx
Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Failed GetHelloWorldString
Error Message:
Unable to create instance of class HelloWorld.Test.ProductContollerTest. Error: System.BadImageFormatException: Could not load file or assembly 'HelloWorldAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format..
Stack Trace:
at HelloWorld.Test.ProductContollerTest..ctor()
- ***Error Message:***
*
**
> Unable to create instance of class
> HelloWorld.Test.ProductContollerTest. Error:
> System.BadImageFormatException: Could not load file or assembly
> 'HelloWorldAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
> or one of its dependencies. An attempt was made to load a program with
> an incorrect format..
**
*
请在团队服务中找到下面的配置详细信息:
Stack Trace:
at HelloWorld.Test.ProductContollerTest..ctor()
Failed GetAllProductListTest
Test Run Failed.
Results File: C:\a\1\TestResults\buildguest_TASKAGENT5-0026 2016-08-22 08_48_07.trx
Total tests: 2. Passed: 0. Failed: 2. Skipped: 0.
Test execution time: 0.4165 Seconds
System.Exception: VSTest Test Run failed with exit code: 1
Publishing Test Results...
Test results remaining: 2
Published Test Run : https://jci.visualstudio.com/Project%20-%20Microservices/_TestManagement/Runs#runId=3191&_a=runCharts
是否可以在VSTest执行步骤中加载依赖(项目)程序集?
答案 0 :(得分:1)
我为时已晚。但是今天我面临着同样的问题,因此我想在这里分享我的解决方案。可能会对某人有所帮助。
注意-我正在使用Visual Studio2017。
对我来说,发生这种情况是因为程序集/项目中使用的处理器架构不一致(32位/ 64位)。
为了解决这个问题,我将所有项目的体系结构设置为64位(x64)。您可以通过在解决方案资源管理器中右键单击解决方案,然后依次单击Properties
> Configuration Properties
并单击Configuration Manager
按钮来完成此操作。
接下来,我将测试的默认处理器体系结构设置为x64。您可以通过点击Test
菜单> Test Settings
> Default Processor Architecture
> x64
来实现。
确保您正在执行在正确路径下生成的库- \ bin \ x64 \ Release \ mytests.dll