【问题标题】:VSTest Build execution - is not loading dependent project assembliesVSTest 构建执行 - 不加载依赖项目程序集
【发布时间】:2016-08-22 09:02:41
【问题描述】:

我创建了一个 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..

**
*

请在 Team Services 中找到以下配置详细信息:

VSTest Configuration Details

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 执行步骤中加载依赖(项目)程序集?

【问题讨论】:

  • 如果直接在本地机器上运行测试,结果是什么?你如何添加参考?项目引用(右键单击项目=>添加引用=>项目)或二进制引用(右键单击项目=>添加引用=>浏览器=>查找 dll 文件)?在此处发布详细的测试代码或在 OneDrive 上分享一个简单的项目。
  • 我也遇到了这个问题,它也适用于我的本地机器。如果我直接使用适当的测试运行程序在 DLL 上运行 vstest.console.exe,则会遇到此错误。与 dotnet test 一起工作,但无法找到可执行文件来运行测试。
  • 您使用的是哪个服务模板?如何添加测试项目,具体测试代码是什么?
  • BadImageFormatException 往往会在您尝试针对不正确的平台架构时发生。尝试将您的平台从 x64 更改为 x86

标签: continuous-integration azure-devops azure-pipelines vstest


【解决方案1】:

我来不及回答这个问题。但是今天我遇到了同样的问题,所以我想在这里分享我的解决方案。它可能对某人有所帮助。
注意 - 我使用的是 Visual Studio 2017。
对我来说,这是因为在程序集/项目中使用的处理器架构(32 位/64 位)不一致。
为了解决这个问题,我将所有项目的架构设置为 64 位 (x64)。您可以通过在解决方案资源管理器中右键单击您的解决方案,然后Properties > Configuration Properties 并单击Configuration Manager 按钮来执行此操作。
接下来,我将测试的默认处理器架构设置为 x64 。您可以通过单击 Test 菜单 > Test Settings > Default Processor Architecture > x64 来执行此操作。
确保您正在执行以正确路径生成的库 - \bin\x64\Release\mytests.dll

【讨论】:

    猜你喜欢
    • 2013-01-30
    • 2010-09-06
    • 1970-01-01
    • 2014-03-19
    • 2012-11-16
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多