我正在尝试构建一个可以读取测试结果的 Azure 管道,以便我可以自动更新测试计划中的状态。我能够打印
Visual Studio Test
任务可以在管道中读取的测试结果的唯一方法是以管理员身份在命令提示符下通过 NUnit-3 控制台运行它。
这是通过 NUnit3 控制台运行的测试结果文件的示例:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<test-run id="0" runstate="Runnable" testcasecount="10134" result="Failed" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0" engine-version="3.15.4.0" clr-version="4.0.30319.42000" start-time="2024-11-21 16:06:59Z" end-time="2024-11-21 16:17:13Z" duration="614.046341">
<command-line>
<![CDATA[ nunit3-console.exe C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\Trintech.Tests.Cadency.dll --where cat=JEActivePeriods ]]>
</command-line>
<filter>
<cat>JEActivePeriods</cat>
</filter>
<test-suite type="Assembly" id="1-12601" name="Trintech.Tests.Cadency.dll" fullname="Trintech.Tests.Cadency.dll" runstate="Runnable" testcasecount="10134" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.891640" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<environment framework-version="3.11.0.0" clr-version="4.0.30319.42000" os-version="Microsoft Windows NT 10.0.22631.0" platform="Win32NT" cwd="C:\Program Files (x86)\NUnit.org\nunit-console" machine-name="PLN-1PPPYD3" user="cstarnes" user-domain="TRINTECH" culture="en-US" uiculture="en-US" os-architecture="x64"/>
<settings>
<setting name="DisposeRunners" value="True"/>
<setting name="WorkDirectory" value="C:\Program Files (x86)\NUnit.org\nunit-console"/>
<setting name="ImageRuntimeVersion" value="4.0.30319"/>
<setting name="ImageTargetFrameworkName" value=".NETFramework,Version=v4.6.1"/>
<setting name="ImageRequiresX86" value="False"/>
<setting name="ImageRequiresDefaultAppDomainAssemblyResolver" value="False"/>
<setting name="TargetRuntimeFramework" value="net-4.6.1"/>
<setting name="NumberOfTestWorkers" value="12"/>
</settings>
<properties>
<property name="ParallelScope" value="Fixtures"/>
<property name="LevelOfParallelism" value="1"/>
<property name="_PID" value="22832"/>
<property name="_APPDOMAIN" value="domain-"/>
</properties>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12602" name="Trintech" fullname="Trintech" runstate="Runnable" testcasecount="10134" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.874161" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12603" name="Tests" fullname="Trintech.Tests" runstate="Runnable" testcasecount="10134" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.873782" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12604" name="Cadency" fullname="Trintech.Tests.Cadency" runstate="Runnable" testcasecount="10134" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.873771" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12605" name="SpecFlow" fullname="Trintech.Tests.Cadency.SpecFlow" runstate="Runnable" testcasecount="10132" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.873763" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12606" name="Features" fullname="Trintech.Tests.Cadency.SpecFlow.Features" runstate="Runnable" testcasecount="10132" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.873748" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestSuite" id="1-12629" name="JournalEntries" fullname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries" runstate="Runnable" testcasecount="1934" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.873676" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties/>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<test-suite type="TestFixture" id="1-6091" name="JEActivePeriodsFeature" fullname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature" classname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature" runstate="Runnable" testcasecount="3" result="Failed" site="Child" start-time="2024-11-21 16:07:01Z" end-time="2024-11-21 16:17:13Z" duration="611.871865" total="3" passed="0" failed="2" warnings="0" inconclusive="0" skipped="1" asserts="0">
<properties>
<property name="Description" value="JEActivePeriods"/>
<property name="Category" value="JEActivePeriods"/>
<property name="Category" value="JERegression"/>
</properties>
<failure>
<message>
<![CDATA[ One or more child tests had errors ]]>
</message>
</failure>
<output>
<![CDATA[ -> Using app.config TRX log file saved to: C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\TrxLogs\TestResults_20241121_100702.trx TRX log file will be saved to: C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\TrxLogs TRX log file saved to: C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\TrxLogs\JEActivePeriods_D1Wo9-10-07-03-166.trx ]]>
</output>
<test-case id="1-6094" name="ActivePeriodsNoErrorMessageWhenExporting" fullname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ActivePeriodsNoErrorMessageWhenExporting" methodname="ActivePeriodsNoErrorMessageWhenExporting" classname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature" runstate="Runnable" seed="785896656" result="Failed" label="Error" start-time="2024-11-21 16:07:04Z" end-time="2024-11-21 16:17:09Z" duration="605.048497" asserts="0">
<properties>
<property name="Description" value="Active Periods: No Error Message when exporting"/>
<property name="Category" value="112271"/>
</properties>
<failure>
<message>
<![CDATA[ OpenQA.Selenium.WebDriverException : Failed to find element with locator By.XPath: //a[contains(@href, 'Certification/Dashboard/Index')]. Error message: disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.86) TearDown : OpenQA.Selenium.WebDriverException : disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.86) ]]>
</message>
<stack-trace>
< in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Utils\Browser.cs:line 438 at Trintech.Tests.Utils.Browser.FindElement[T](By locator, Boolean waitForVisible, Boolean checkForAngular) in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Utils\Browser.cs:line 397 at Trintech.Tests.Utils.Browser.FindElement(By locator, Boolean waitForVisible) in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Utils\Browser.cs:line 384 at Trintech.Tests.Cadency.CertificationPage.OpenManagementMenu() in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\Pages\Certification\CertificationPage.cs:line 1085 at Trintech.Tests.Cadency.ManagementDashboardSteps.WhenINavigateToTheActivePeriodsPage() in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Steps\Certification\Management\ManagementDashboardSteps.cs:line 1736 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ScenarioCleanup() at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ActivePeriodsNoErrorMessageWhenExporting() in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Features\JournalEntries\JEActivePeriods.feature:line 78 --TearDown at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.WebDriver.get_WindowHandles() at Trintech.Tests.Cadency.Hooks.AfterScenario(FeatureContext featureContext, ScenarioContext scenarioContext) in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Hooks\Hooks.cs:line 764 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd() at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ScenarioTearDown() ]]>
</stack-trace>
</failure>
<output>
<![CDATA[ Given I login as 'jeautouser' -> done: LoginSteps.GivenILoginAs("jeautouser") (5.6s) When I Navigate to Certification Page -> done: DashboardPageSteps.WhenINavigateToCertificationPage() (3.1s) And I navigate to the Active Periods page -> error: Failed to find element with locator By.XPath: //a[contains(@href, 'Certification/Dashboard/Index')]. Error message: disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.86) Then I Verify Export button is Working on Active Periods -> skipped because of previous errors And I validate that active periods file is exported within 30 seconds -> skipped because of previous errors Then I verify the Active Periods export: --- table step argument --- | Display Name | Period | Year | Start | End | Effective Date | Status | -> skipped because of previous errors TRX log file saved to: C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\TrxLogs\JEActivePeriods_D1Wo9-10-07-03-166.trx ]]>
</output>
</test-case>
<test-case id="1-6092" name="CorrectErrorMessageAppearsWhenDeletingActivePeriodInUseBySR" fullname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.CorrectErrorMessageAppearsWhenDeletingActivePeriodInUseBySR" methodname="CorrectErrorMessageAppearsWhenDeletingActivePeriodInUseBySR" classname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature" runstate="Ignored" seed="1867787410" result="Skipped" label="Ignored" start-time="2024-11-21 16:17:09Z" end-time="2024-11-21 16:17:09Z" duration="0.000759" asserts="0">
<properties>
<property name="Description" value="Correct error message appears when deleting Active Period in use by SR"/>
<property name="_SKIPREASON" value="Ignored scenario"/>
<property name="Category" value="122627"/>
</properties>
<reason>
<message>
<![CDATA[ Ignored scenario ]]>
</message>
</reason>
</test-case>
<test-case id="1-6093" name="ModernizedActivePeriodsValidateTheLayoutAndFunctionalityOfTheActivePeriodsDashboard" fullname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ModernizedActivePeriodsValidateTheLayoutAndFunctionalityOfTheActivePeriodsDashboard" methodname="ModernizedActivePeriodsValidateTheLayoutAndFunctionalityOfTheActivePeriodsDashboard" classname="Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature" runstate="Runnable" seed="29488523" result="Failed" label="Error" start-time="2024-11-21 16:17:09Z" end-time="2024-11-21 16:17:09Z" duration="0.018234" asserts="0">
<properties>
<property name="Description" value="Modernized Active Periods: Validate the layout and functionality of the active periods dashboard"/>
<property name="Category" value="123994"/>
</properties>
<failure>
<message>
<![CDATA[ OpenQA.Selenium.WebDriverException : disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.86) TearDown : System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary. ]]>
</message>
<stack-trace>
<![CDATA[ at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.WebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.CookieJar.GetAllCookies() at OpenQA.Selenium.CookieJar.get_AllCookies() at Trintech.Tests.Cadency.Hooks.BeforeScenario(FeatureContext featureContext, ScenarioContext scenarioContext) in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Hooks\Hooks.cs:line 480 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ScenarioStart() at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ModernizedActivePeriodsValidateTheLayoutAndFunctionalityOfTheActivePeriodsDashboard() in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Features\JournalEntries\JEActivePeriods.feature:line 15 --TearDown at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Trintech.Tests.Cadency.Hooks.AfterScenario(FeatureContext featureContext, ScenarioContext scenarioContext) in C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\SpecFlow\Hooks\Hooks.cs:line 743 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd() at Trintech.Tests.Cadency.SpecFlow.Features.JournalEntries.JEActivePeriodsFeature.ScenarioTearDown() ]]>
</stack-trace>
</failure>
<output>
<![CDATA[ -> warning: The previous ScenarioContext was not disposed. TRX log file saved to: C:\Users\cstarnes\source\repos\CadencyAuto\CadencyAuto\Trintech.Tests.Cadency\bin\Debug\TrxLogs\JEActivePeriods_D1Wo9-10-07-03-166.trx ]]>
</output>
</test-case>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-run>
我希望能够做以下两件事之一:
通过 Azure Pipeline 任务运行 NUnit-3 控制台,这样我就不再需要在外部运行它,然后手动将其结果文件粘贴到“测试结果文件夹”中。请记住,目前我只能以管理员身份通过命令提示符运行 Nunit3 控制台。不确定我必须获得什么权限才能对 Azule 管道任务拥有命令提示符管理员权限,或者是否有一种方法可以在不以管理员身份运行它的情况下运行它。现在我似乎只能使用“命令行”任务以非管理员身份在管道上运行命令行脚本。
以另一种方式获取相同的测试结果格式,或者至少以一种也可以解释为 Azure Pipeline 中的 Visual Studio 测试任务的方式。
您可以在 Azure DevOps 管道中运行 NUnit-3 控制台,无需管理员权限。
参考下面的例子:
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
steps:
- task: PowerShell@2
displayName: 'Install choco'
inputs:
targetType: 'inline'
script: |
Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- task: CmdLine@2
displayName: 'Install nunit-console-runner'
inputs:
script: |
choco install nunit-console-runner
workingDirectory: 'PrimeService.Tests'
- task: CmdLine@2
displayName: 'Run tests'
inputs:
script: 'nunit3-console.exe --result=TestResult.xml;format=nunit3 {Path to your assembly}'
- task: PublishTestResults@2
displayName: 'Publish test result'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/TestResult.xml'
结果: