tfs 2012 failed to run test case: Error calling Initialization method for test class - mtm

Recently we found our integration test failed unexpected with following exception:
We even remeber that we have changed nothing to TFS BDT workflow and test case.
Error exception:
Error calling Initialization method for test class
UITestDemo.UITestDemo01:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: To
run tests that interact with the desktop, you must set up the test
agent to run as an interactive process. For more information, see "How
to: Set Up Your Test Agent to Run Tests That Interact with the
Desktop" (http://go.microsoft.com/fwlink/?LinkId=255012) If you are
running the tests as part of your team build, you must also set up the
build agent to run as an interactive process. For more information,
see "How to: Configure and Run Scheduled Tests After Building Your
Application" (http://go.microsoft.com/fwlink/?LinkId=254735)
Error Stack Trace:
Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()
Microsoft.VisualStudio.TestTools.UITesting.CodedUITestExtensionExecution.BeforeTestInitialize(Object
sender, BeforeTestInitializeEventArgs e)
Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecution.RaiseBeforeTestInitialize(BeforeTestInitializeEventArgs
args)
Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.RunInitializeMethod()
We have no idea how to fix it.

After investigation, we found that test is running by account: "computerName$" on environment, not the specified account in test controller settings.
<?xml version="1.0" encoding="utf-8"?>
<SystemInformation>
<ComputerName>ComputerName</ComputerName>
<UserName>ComputerName$</UserName>
<UserDomainName>WORKGROUP</UserDomainName>
<OSInfo>
<OSName>Microsoft Windows Server 2008 R2 Enterprise </OSName>
<OSVersion>Microsoft Windows NT 6.1.7601 Service Pack 1</OSVersion>
<SystemDirectory>C:\Windows\system32</SystemDirectory>
<SystemLocale>English (United States)</SystemLocale>
<UserLocale>English (United States)</UserLocale>
</OSInfo>
<ProcessorInfo>
<Processor0>
<ProcessorName>Intel(R) Xeon(R) CPU E5-2690 v2 # 3.00GHz</ProcessorName>
<ProcessorFamily>Intel64 Family 6 Model 62 Stepping 4</ProcessorFamily>
<ProcessorSpeed>2999</ProcessorSpeed>
</Processor0>
<Error>NoError</Error>
</ProcessorInfo>
<MemoryInfo>
<TotalPhysicalMemory>4945</TotalPhysicalMemory>
<AvailablePhysicalMemory>1541</AvailablePhysicalMemory>
<MemoryLoad>68</MemoryLoad>
<TotalVirtualMemory>2047</TotalVirtualMemory>
<AvailableVirtualMemory>1432</AvailableVirtualMemory>
<Error>NoError</Error>
</MemoryInfo>
<ScreenInfo>
<ScreenHeight>768</ScreenHeight>
<ScreenWidth>1024</ScreenWidth>
<BitsPerPixel>32</BitsPerPixel>
</ScreenInfo>
<IEInfo>
<IEVersion>11.0.9600.16428</IEVersion>
<Error>NoError</Error>
</IEInfo>
</SystemInformation>
Solution:
We open the using test settings in MTM test settings manager.
And recheck each environment should run test on correct role.
Then retest run pass.

Related

GenerateEFSQLScripts fails when trying to publish to IIS using Web Deploy from TeamCity

Running into a total dead-end here.
I've created a Publish Profile for a .net6 application that we want to publish to IIS with Web Deploy. In the Entity Framework Migration section, the option to "Apply this migration on publish" is selected.
When manually clicking publish, everything works. However, we want to automate this in TeamCity using the .NET build runner. The publish step fails at:
Generating Entity Framework SQL Scripts...
Executing command: dotnet ef migrations script --no-build --idempotent --configuration Release --output "C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api\obj\Release\net6.0\PubTmp\EFSQLScripts\MySolution.Data.MyContext.sql" --context MySolution.Data.MyContext
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(221,5): error : Entity Framework SQL Script generation failed
Internal error message details: BuildMessage1 0 Text DefaultMessage ERROR 400682522803500 tags:'tc:parseServiceMessagesInside'
Error message is logged
Build FAILED.
I cannot find any specific error messages anywhere in any log. Looking in the Microsoft.NET.Sdk.Publish.TransformFiles.targets file shows that it's failing on GenerateEFSQLScripts - an MSBuild command that executes dotnet ef under the covers.
I thought this might be a case of dotnet ef not being installed on the build agent. But when I manually run the command myself from C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api, it succeeds, and the SQL scripts are successfully created.
I also thought it might just be a case of the command being run in the wrong directory (i.e. in the root MySolution folder rather than the MySolution.Api folder), but explicitly setting the working directly fails at the same point, with the same error.
Has anyone seen this before? Or could point me to where an actual error might be located?

QA Pipeline Run failing in Azure

I'm using Testcomplete as my automation tool. Our pipeline is in Azure and its newly created for QA runs. The test VM was set up in VMSS in Azure. I'm using TestExecute as my test runner. Testexecute is already installed in the VM. When i run the pipeline, I'm getting an error which says
</RunSettings>
**************** Starting test execution *********************
C:\a\_tool\VsTest\17.4.0-preview-20220726-02\x64\tools\net462\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "#C:\a\_temp\4hdijfnknda.tmp"
Microsoft (R) Test Execution Command Line Tool Version 17.4.0-preview-20220726-02 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe "C:\a\1\s\GrizzlyMatters.pjs"
/Settings:"C:\a\_temp\ro5un5cn0ip.tmp.runsettings"
/Logger:"trx"
/TestAdapterPath:"C:\a\1\s\TestCompleteAdapter"
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
##[error]Failed to get a list of tests from the "C:\a\1\s\GrizzlyMatters.pjs" file due to the following error: Unable to connect to TestExecute: it is running with different rights, or its state is incorrect. Please close it and try again.
No test is available in C:\a\1\s\GrizzlyMatters.pjs. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: C:\a\_temp\TestResults\AzDevOps_vmliaqa000008_2022-09-01_14_51_35.trx
##[error]Test Run Failed.
Vstest.console.exe exited with code 1.
**************** Completed test execution *********************
Test results files: C:\a\_temp\TestResults\AzDevOps_vmliaqa000008_2022-09-01_14_51_35.trx
No Result Found to Publish 'C:\a\_temp\TestResults\AzDevOps_vmliaqa000008_2022-09-01_14_51_35.trx'.
Created test run: 2724386
Publishing test results: 0
Publishing test results to test run '2724386'.
TestResults To Publish 0, Test run id:2724386
Published test results: 0
Publishing Attachments: 1
Execution Result Code 1 is non zero, checking for failed results
Completed TestExecution Model...
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\2.205.0\Modules\DTAExecutionHost.exe' failed with exit code 1
##[error]Vstest failed with error. Check logs for failures. There might be failed tests.
Finishing: VsTest - testAssemblies
I've researched everything possible to get a solution. I'm not sure what I need to do. I'm attaching the screenshot of the pipeline config and the error.
Screenshots
Pipeline config 1:
Pipeline config 2:
Pipeline config 3:
Pipeline Run Error:

coverlet coverage report resulting in Microsoft.VisualStudio.Coverage.VanguardException

I'm trying to integrate Cobertura report generation in my azure pipeline. For that I've added coverlet.collector 3.0.3 in my .Net core test projects. Below is my yaml command for test run
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '**/*Test/*.csproj'
arguments: '--collect:"XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx'
publishTestResults: false
I use Reportgenerator task, to merge & publish coverage reports. This all works fine in one branch of my code ( an old branch, on which I started setting up pipeline a while back ). But when I'm trying to point to latest branch in the pipeline, I get error as below
Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason
I've checked almost everything in two branches, Microsoft.Net.Test.SDK, coverlet.collector, both are of identical version. I'm not sure what is making difference between 2 branches and what differences I should be looking for between 2 code branches, that could lead to such issue.
Full log in case of success and failure is added below.
Success(when using old branch)
C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work\489\s\XXXX.Business.Test\XXXX.Business.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work\489\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002
Copyright (c) Microsoft Corporation. All rights reserved.
Results File: I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_18_04.trx
Attachments:
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\5f62864f-6c2c-4188-ac02-0dc536b464b3\coverage.cobertura.xml
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\5f62864f-6c2c-4188-ac02-0dc536b464b3\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01.04_17_58.coverage
Test Run Successful.
Total tests: 6
Passed: 6
Total time: 3.8813 Seconds
Failure(when pointing to new branch)
C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work\489\s\XXXX.Test\XXXXBusiness.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work\489\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason.'. More details: ..
Results File: I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_12_42.trx
Attachments:
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\3839c24a-e17d-4d0d-9953-359388d5a940\coverage.cobertura.xml
Test Run Failed.
Total tests: 6
Passed: 6
I also came across this issue thread : https://github.com/microsoft/azure-pipelines-agent/issues/2839 where user suspected it to be an agent upgrade issue, but that does not seems to be the case for me, as I'm able to run it successfully for one branch of code.
Any suggestion or guidance is appreciated.
As I raised this question with Coverlet team, I got a quick response from them. They noticed something that I totally missed.
Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002
This was coming in my success log, which meant that Microsoft code coverage was running in parallel with Coverlet code coverage. They suspected we can get some odd errors if you have two code coverage collectors running at the same time, and that some timing issue between how tests are run in the two branches leads to the different behavior.
As soon as I disabled Microsoft code coverage in my .runsettings file, the issue got resolved
Earlier:
<DataCollector friendlyName="XPlat code coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Now
<DataCollector friendlyName="XPlat code coverage">

VSTS - Build a Docker Image

I have a .NET Core repo in VSTS. I'm trying to create a Build pipeline that builds a Docker image and adds it to my Azure Container Registry. My Build pipeline has a Docker task. This task has the "Build an image" action selected. This action relies on my Dockerfile, which looks like this:
FROM microsoft/dotnet:2.1.2-runtime-nanoserver-1803
# Install .NET Core
ENV DOTNET_VERSION 2.1.2
When my Build pipeline runs, I get an error that says:
failed to register layer: re-exec error: exit status 1: output: ProcessUtilityVMImage \\?\C:\ProgramData\docker\windowsfilter\82aba535faccd8bf0e5ce3c122247672fa671214000a12c5481972212c5e2ca0\UtilityVM: The system cannot find the path specified.
##[error]C:\Program Files\Docker\docker.exe failed with return code: 1
Why am I getting this error? How do I fix it?
It should be the same issue with this one : https://github.com/Microsoft/vsts-tasks/issues/6510
Seems it still have some issues with nanoserver-1803
Just try to setup and host a custom agent on Azure VM, then check it again.
https://github.com/Microsoft/vsts-tasks/issues/6510#issuecomment-370152300
I found maybe an explication about this error: VSTS agents seem not
support nanoserver-1709 actually. Maybe this will change with the next
version 1803.
See details here: Microsoft/vsts-agent#1393
When I setup and host a custom agent on a machine on Azure, it's
working. So it's not a bug with this task. I close this issue. Thanks!

TeamCity ".Net Process Runner" hangs

We have started migrating our one of several projects to team city as part of CI. Below is how we have setup teamcity build. We are trying to deploy WebSite.
1) Build Step 1 (Package installation)
Using "command line " runner type install required package.
2) Build Step 2 (Build)
Using Runner type "Visual Studio (sln)" (Visual Studio 2010) build website.
3) Build Step 3 (Deploy Web Site)
Using ".Net Process Runner", deployer.exe (x86 built with .Net Framework 4) deploy site.
Deployer.exe reads config file. Config file contains "BuildId", "Environment" and "Servers" where we want build to be pushed.
<buildType id="bt52">
<env name="Debug">
<server path="SERVER1" />
</env>
<env name="QA">
<server path="SERVER2" />
<server path="SERVER3" />
</env>
<env name="UAT">
<server path="SERVER4" />
<server path="SERVER5" />
</env>
</buildType>
Deployer.exe is called with required parameters as below. Which reads config and deploys site to Server2 and Server3.
Deployer.exe "bt52" "QA" "siteQA" "E:\BuildAgent\work\2483052e33e5e1e8\src\diy\" msdeploy.exe
Problem area is step #3.
When we run deployer.exe using .Net process runner as part of team city we see its hanging and not responsind sometime even for 45 minutes. When we try to execute same deployer.exe from build server using command line script executes within couple of seconds.
E:\TeamCity_custom_applications\deployer>Deployer.exe farm1-1 QA siteQA E:\BuildAgent\work\2483052e33e5e1e8\src\diy\ msdeploy.exe
Info
: Processing batch run ... Info : Processing command ...msdeploy.exe
-verb:sync -source:contentPath="E:\BuildAgent\work\2483052e33e5e1e8\src\diy\" -dest:contentPath="siteQA",wmsvc="SERVER2",userName="*****",password="******",authType="Basic"-skip:objectName=filePath,absolutePath=web.config -skip:objectName=dirPath,absolutePath="bin" -enableRule:DoNotDeleteRule -allowUntrusted Info : output >>Total changes: 0 (0 added, 0 deleted, 0 updated, 0 parameters changed, 0
bytes copied) Info : error >>(none) Info : ExitCode >> 0 Info :
Processing command ...msdeploy.exe -verb:sync
-source:contentPath="E:\BuildAgent\work\2483052e33e5e1e8\src\diy\" -dest:contentPath="siteQA",wmsvc="SERVER3",userName="******",password="******",authType="Basic"
-skip:objectName=filePath,absolutePath=web.config -skip:objectName=dirPath,absolutePath="bin" -enableRule:DoNotDeleteRule -allowUntrusted Info : output >>Total changes: 0 (0 added, 0 deleted, 0 updated, 0 parameters ch anged, 0
bytes copied) Info : error >>(none) Info : ExitCode >> 0
Info: Deploy Script Complete.
One more thing we observed is running deployer.exe through teamcity I see that site content gets copied but only for 1 server and teamcity build status stays in "Running" mode. I am wondering if someone can please put little bit of insight on how can I look into this issue.
Update 1:
Thanks for your time looking into it !! What we ended up doing is, Instead of running command "msdeploy.exe" from "cmd.exe" we added "msdeploy.exe" location as Environment variable and executed "msdeploy.exe" in loop for # of servers. This has resolved issue of hanging. Now I am just curious to know why would it behave in such manner where if you execute "msdeploy.exe" from "cmd.exe" it would hang while running directly "msdeploy.exe" it would execute successfully. Any insight into same would be greatly appreciated.
Update 2:
I have added image which explains behavior using process explorer. If we kill msdeploy.exe from process explorer than for next all deployments to that server will not have the issue of build hanging. Please see below image
To be honest, it sounds like you're running into issues with redirecting input/output streams. TeamCity is running your application in a totally headless environment and then you, in turn, are attempting to redirect and parse the output of msdeploy.exe
If that's the case, I'd recommend looking into using the MSDeploy API instead of msdeploy.exe. The latter is just a command line wrapper for the former, so all the functionality is available to you. There's a sample deployment application available on the IIS blog if you need help getting started.
It seems you have NUnit build step configured in TeamCity and invoke cmd.exe from your test. This looks like an issue with the test code then. Most probably it will reproduce without TeamCity if you run the test in question with NUnit directly.
As Richard noted, most probably the issue root cause is related to stdin/stdout processing.
If you want to fix it in your code, you can try to experiment by explicitly closing stdin or the other way around, try writing something into it, etc.
Work around we did is, we observed msdeploy doesn't take more than 3-5 seconds to execute and deploy (Even for our biggest project which is almost 300mb website). So we set timeout of 20 seconds. So far since last 1 weeks we have not seen any issue with it and hopefully it will not cause more trouble but still we are not sure why such behavior.

Resources