Avatar of Christian Palacios
Christian Palacios
Flag for Canada asked on

Problem running xUnit tests inside a batch file when set in a scheduled task

I'm not sure anyone can help since this is just a unique set up, but I'm hoping someone can shed some light on this issue.  I have a batch file that runs an MSBuild.exe command and then runs some xUnit tests using the xunit.console.x86.exe application.  I'm running five different commands similar to the one below.

C:\Users\sve\.nuget\packages\xunit.runner.console\2.4.1\tools\net472\xunit.console.x86.exe C:\SDS_IT\build\BuildTests\bin\Debug\BuildTests.dll -xml C:\xunit-test-results\build-test-result.xml

So the command runs some tests and then puts the output it an XML file.  If I run the batch file manually through a command window or through a PowerShell window, it runs fine every time.  But if I set a scheduled task to run this batch file, the task will successfully run two times in a row, but then on the third time, it hangs on the longest xUnit test.  I don't understand how it runs fine a couple of times and then it hangs on the third time.  I have tried this many times and this is always the case.  The scheduled task is set to run every hour.

Please let me know if you have an insight!  Ask any questions you may have!

Thanks in advance!
Powershell* Packages* task schedulerXMLMicrosoft Visual Studio

Avatar of undefined
Last Comment
Christian Palacios

8/22/2022 - Mon
Chirag Nagrekar

Assume these features are selected when you had configured task.

Raghu Mutalikdesai

In the batch file, can you try this?
cmd /c C:\Users\sve\.nuget\packages\xunit.runner.console\2.4.1\tools\net472\xunit.console.x86.exe C:\SDS_IT\build\BuildTests\bin\Debug\BuildTests.dll -xml C:\xunit-test-results\build-test-result.xml

Open in new window

Also consider using MSBuild variables for long path prefix.
Christian Palacios

Thank you.  Hi Chirag, yes, those are the settings I have.

Thanks Raghu, but it didn't seem to pop up.  I'm thinking if something is stuck after the script runs the first time.  Is there an option to ensure the script completely ends/closes everything after it runs successfully for the first time through a scheduled task?

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Christian Palacios

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.