Xunit not working using Visual Studio Team Service

2019-05-23 15:42发布

After following several blogs detailing how to get xUnit working with Team Services Build vNext:

None of which worked for me. From examining the build logs I get the following warnings for each of my test assemblies.

--------------------
 Warning: [xUnit.net 00:00:00.1644156] Exception discovering tests from CHO.SAM.Business.Test: System.BadImageFormatException: 
 Could not load file or assembly 'c:\_Work\473cef3c\CHO\CHO.ALL\Tests\CHO.SAM.Business.Test\CHO.SAM.Business.Test\bin\Debug\xunit.execution.desktop.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
--------------------

Has anyone seen this before? and if so did you figure out a solution?

My thoughts are; my test projects are compiled using .NET Framework 4.6, I was wondering if this could be causing the problem? If so I would have to move over to nUnit or something as I don't feel it's right to change the compilation just to use a single test framework.

5条回答
不美不萌又怎样
2楼-- · 2019-05-23 16:06

I ran into this issue when using a .Net Core class library to run my xUnit tests against a .Net Core Web Project (.Net Framework). What solved the issue for me was to change the default processor for running test to X64 in VS2015 via:

Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64

This solution was posted by @RehanSaeed here https://github.com/dotnet/cli/issues/3103

查看更多
唯我独甜
3楼-- · 2019-05-23 16:21

I had this same issue. Adding a UI test did not fix it for me. I found two alternatives that work:

  1. use .net 4.5

    OR

  2. Set the advanced options of the VSTest task to use 2013 instead of 2015.

Hopefully this will be fixed soon.

查看更多
Melony?
4楼-- · 2019-05-23 16:26

This error is normally caused by a x64 compiled assembly running on x86 test runner or vice versa. Check the solution build configuration that is being run.

查看更多
虎瘦雄心在
5楼-- · 2019-05-23 16:30

In the end, I added a Visual Studio Coded UI test project and removed all it's contents (a class), it's empty!

I'm assuming it's added a reference or something that the build server felt it needed.

I am now getting my unit tests discovered, running and with code coverage.

Wierd!

It works, but I don't know why...

查看更多
相关推荐>>
6楼-- · 2019-05-23 16:31
  • Add "/Framework:Framework45" to "Advanced/Other console options" (to run under .NET 4.5)
    or
  • Add "/Framework:Framework40" to "Advanced/Other console options" (to run under .NET 4.0)
    or
  • Change "Advanced/VSTest version" to "Visual Studio 2013" (to run under .NET 3.5)
查看更多
登录 后发表回答