我有一个集成测试,该测试在本地成功运行,但是在Azure DevOps上被冻结。
如果只有一个测试类,它将在Azure DevOps上运行。
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core 4.6.27414.05)
[xUnit.net 00:00:02.04] Discovering: myapp.IntegrationTests
[xUnit.net 00:00:02.12] Discovered: myapp.IntegrationTests
[xUnit.net 00:00:02.13] Starting: myapp.IntegrationTests
Passed myapp.IntegrationTests.class1.case1
[xUnit.net 00:00:04.39] Finished: myapp.IntegrationTests
Passed myapp.IntegrationTests.class1.case2
Results File: D:\a\1\s\TestResults\VssAdministrator_fv-az601_2019-05-02_16_54_26.trx
Total tests: 2. Passed: 2. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 6.4121 Seconds
但是,当有多个测试类文件时,它将冻结在下面的最后一行。
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core 4.6.27414.05)
[xUnit.net 00:00:02.72] Discovering: myapp.IntegrationTests
[xUnit.net 00:00:02.78] Discovered: myapp.IntegrationTests
[xUnit.net 00:00:02.79] Starting: myapp.IntegrationTests
以下是一些信息: 它在VS 2017中本地运行,如下所示。请注意4.6.27110.04是不同的。
[02/05/2019 17:28:48 Informational] [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core **4.6.27110.04**)
该项目是.NET Core 2.2
下面是集成测试程序集的日志
##[section]Starting: Integration Test Assemblies
==============================================================================
Task : Visual Studio Test
Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version : 2.150.9
Author : Microsoft Corporation
Help : [More information](https://go.microsoft.com/fwlink/?LinkId=835764)
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : D:\a\1\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
Attempting to find vstest.console from a visual studio build tools installation.
Attempting to find vstest.console from a visual studio installation.
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : true
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Test selector : Test assemblies
Test assemblies : **\*.IntegrationTests.dll,!**\obj\**
Test filter criteria : null
Search folder : D:\a\1\s
Run settings file : D:\a\1\s
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
Rerun failed tests: false
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
Attempting to find vstest.console from a visual studio build tools installation.
Attempting to find vstest.console from a visual studio installation.
========================================================
======================================================
[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\a\_temp\89a681e1-6cfc-11e9-a74f-a3bedc500b32.txt
Microsoft (R) Test Execution Command Line Tool Version 15.9.1
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe
"D:\a\1\s\src\myapp.IntegrationTests\bin\Release\netcoreapp2.2\myapp.IntegrationTests.dll"
/logger:"trx"
/TestAdapterPath:"D:\a\1\s"
Starting test execution, please wait...
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.1 (64-bit .NET Core 4.6.27414.05)
[xUnit.net 00:00:01.97] Discovering: myapp.IntegrationTests
[xUnit.net 00:00:02.03] Discovered: myapp.IntegrationTests
[xUnit.net 00:00:02.04] Starting: myapp.IntegrationTests
[xUnit.net 00:00:06.47] Finished: myapp.IntegrationTests
Passed myapp.IntegrationTests.class2.case1
Results File: D:\a\1\s\TestResults\VssAdministrator_fv-az606_2019-05-02_17_06_04.trx
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 8.5422 Seconds
##[section]Async Command Start: Publish test results
Publishing test results to test run '1019422'
Test results remaining: 1. Test run id: 1019422
Published Test Run : https://dev.azure.com/mydomain/_TestManagement/Runs#runId=1019422&_a=runCharts
##[section]Async Command End: Publish test results
##[section]Finishing: Integration Test Assemblies
下面的项目参考
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
该代码仅使用[Fact]
,非常简单。
同样,如果有多个类,它将永远运行。
更新
public class A : Base
{
[Fact]
public async Task Case1()
{
}
}
public class B : Base
{
[Fact]
public async Task Case1()
{
}
}
public class Base
{
protected static WebResponse WebResponse { get; set; }
private static bool IsTrue { get; set; } = true;
private static readonly object ObjectLock = new object();
public BaseTest()
{
if(IsTrue){
lock (ObjectLock)
{
if (IsTrue){
WebResponse = GetWebAsync().Result;
IsTrue = false;
}
}
}
}
}
我需要针对上述所有子类在Base类中运行设置,但我认为这可能会导致问题。
如果是问题所在,如何避免它并改进代码?
答案 0 :(得分:0)
我将其设置为以下
"parallelizeTestCollections": false
或通过Collection
属性将其设置为顺序运行