Unit tests slow execution on build server - unit-testing

I have a .NET solution that contains some Service Fabric library projects (.NET Standard 2.0) that are published as nuget packages. The unit-test projects in the solution (.NET Core 2.0) are using xUnit.
I noticed the tests are taking too much time when running on the build server, comparing to previous builds.
I tried running the tests in my local machine using Reshaper/Visual Studio or a powershell script and it takes less than 5 minutes:
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
Get-ChildItem -recurse *tests.csproj | % {
dotnet test $_.FullName --no-build --no-restore;
}
$stopwatch.Stop()
Write-Host $stopwatch.Elapsed
But in Azure Devops the unit-testing task took more than 27 minutes to finish!!!
This is the Build pipeline/unit test task:
Any idea on what is going on?

Found a solution in Regression: dotnet test hangs for 15 minutes after test run completed on mac and linux.
Adding the following parameter to the arguments of the dotnet build task did the trick:
-nodereuse:false
BTW the build agents are Windows machines, not mac or linux as mentioned in the above issue.

Related

UWP Continuous Integration: How to automatically execute my test part inside of my Unit Test APP by MSTest commandline

My Universal Windows Application now is able to deploy and I try to associate my gitlab CI service to it,But failed to execute the test part automatically with MSTest commandline, which is separated from UWP and work as an Unit Test Application.
I had found so many solutions,telling me such as: Package my app Firstly before using the vstest.console command line to test(Cannot continuous integrate I guess), Making my Test APP and use the project's .dllfiles ,as the testcontainer, to test(Actually I cannot found out the .dll file)
What should I do next If I want to integrate APP with automatically testing part?
Here is the environment:
Windows 10 OS
Visual Stdio 2017(Includes Windows_10_14393 SDK)
GitLab + Windows Runner(same environment as PC)
Test Execution Command Line Tool Version 15.0.27309.0
And my DOM in Solution:
--+-- APP Solution
------+---APP1(University Windows Application)
------+---TestAPP1(Unit Test Application)
You have to just build the test pan p in Release mode and use the .appxreciepe as argument to run vstest.console. no need to build an appx package

Build of a ASP.NET Core RC2 project fails on Visual Studio Team Services

I have an ASP.NET Core RC2 project hosted with Git in Visual Studio Team Services.
When I try build using the Visual Studio Build task in Build vNext I get the following error "The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk."
I can build locally using VS2015 with the .Net Core SDK RC2.
Is there a way to get Asp.Net core RC2 SDK on to the hosted agent - I dont really want to create a custom one.
Anyone know when the .Net Core RC2 SDK will be added the build agent or where to even look for that information.
Thanks.
Unfortunately you'll have to create your own private agent with Visual Studio 2015 Update 2 and the latest dotnet tools. The team consider .NET Core 1 RC2 as pre-release software, and don't as a rule install pre-release software on the hosted agent image.
You can add a PowerShell script task in your build definition to install the required runtime for Asp.Net Core project.
# bootstrap DNVM into this session.
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
# load up the global.json so we can find the DNX version
$globalJson = Get-Content -Path $PSScriptRoot\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
if($globalJson)
{
$dnxVersion = $globalJson.sdk.version
}
else
{
Write-Warning "Unable to locate global.json to determine using 'latest'"
$dnxVersion = "latest"
}
# install DNX
# only installs the default (x86, clr) runtime of the framework.
# If you need additional architectures or runtimes you should add additional calls
# ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
# run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
Refer to this link for details: Build and Deploy your ASP.NET 5 Application to an Azure Web App

Error while running Nunit 3.0.1 in Bamboo CI

I am running NUnit 3.0.1 as a build task in Bamboo CI after the MSbuild task.
I am getting the following error
Invalid argument: -xml=TestResult.xml
Running a bat file as specified in How to run NUnit Runner in Atlassian Bamboo with NUnit 3 also didnt work as it gave me the error nunit3-console.exe is not a recognized command
Bamboo CI doesn't appear to fully support NUnit 3.X yet, see the issue here.
The error you are seeing is because NUnit 3 no longer supports the -xml option.
Looking at the notes on the Bamboo issue, it looks like the best appoach is to run NUnit3 as a script task (using the option --result=YOURPATH;format:nunit2 to format the results as NUnit2 would have), and then adding an NUnit Parser Task to merge the results back in.

How to run Windows phone 8 & 8.1 Unit tests in jenkins [Visual studio 2013]

We use Jenkins as our CI, and im looking to have Jenkins run visual studio tests. Ive figured out how to have Jenkins use vstest.console.exe for desktop applications, but im not sure how to get that to work for windows phone 8.1 tests. I'm running vstest.console.exe against my unit test project's appx file, but im getting:
Error: App package ...appx does not has test executor entry point. For
running unit tests for Windows Store apps, create app package using
Windows Store app Unit Test Library project.
Any help getting the program to work thorugh command line would be of big help, but if there is a short cut to run it through jenkins that would be even better.
I found an answer to my problem. Make sure to use /InIsolation, and use /Settings:{settingsFile}. For some reason vstest.console.exe cant run the unit tests for windows phone without specifically setting a settingsfile. In jenkins/vsTestrunner there is an option to set the settings file. You will likley still get an error regarding running the test in non-interactive way on jenkins, but there are a few stackoverflow posts about this already.

How to automate installer testing

I'm wondering if anyone has any best practices for automating the testing of installers on various machines with potentially different hardware / software profiles and by specifying various options to the installer. The idea would be that I could write "unit test like" code to set up a machine, run the installer, then test that certain things are true. Tests might look similar to:
Test:
Boot Machine without IIS
Run Installer
Assert Installer Had Errors
Test:
Boot Machine with IIS
Run Installer
Assert Installer Ran
Test_Fixture:
SetUp:
Boot Machine with IIS
Test:
Run Installer without IIS install
Assert Website Not Installed
Test:
Run Installer with IIS install
Assert Website Installed
I know I could create lots of VMs, but waiting for a VM to boot for each functional test sounds like way more work than I want. What I really want is a way to virtualize the installer environment. Any suggestions?
We have created a set of VMs and find it is very easy to manage. We run the tests for 13 different Windows installers over night. The VMs we have created our very bare bones, so it is possible to run a number of tests in parallel.
If you have the installer runnable from the command line, it's easy to have a script to call it automatically.
Then you can use a web app testing tool to see it the install was successful, like this one http://seleniumhq.org/ For this you will need an unique way to test a new install - like a page with the current version.