Dotnet test coverage always null - asp.net

I have an issue with test coverage. When I run this command
dotnet test ../XZrcndee.sln --output ../coverage /p:CollectCoverage=true /p:CoverletOutput=results\coverage /p:CoverletOutput=..\results\coverage /p:MergeWith=..\results\coverage.json /p:CoverletOutputFormat="opencover"
It show me that codecoverage is 0
When I try run dotnet test in only one project I got the correct result.
dotnet test ../XZrcndee.Domain.Tests/XZrcndee.Domain.Tests.csproj --output ../coverage /p:CollectCoverage=true /p:CoverletOutput=results\coverage /p:CoverletOutput=..\results\coverage /p:MergeWith=..\results\coverage.json /p:CoverletOutputFormat="opencover"
Do I miss somthing?
Kind Regards

Try this
dotnet test ../XZrcndee.sln --output ../coverage /p:CollectCoverage=true /p:CoverletOutput=results\coverage /p:CoverletOutput=..\results\coverage /p:MergeWith=..\results\coverage.json /p:CoverletOutputFormat="opencover" /maxcpucount:1
make sure to cleanup the "coverage.json" after each run otherwise it will merge results from mulitple runs also.

Related

How to execute the all the tests from the arraylist in .NET Core

We are getting the tests to execute from our testcase management tool and have stored their id in the list .
Example:
List<string> caseid = new List<string>() [ "tc1", "tc2", "tc3" ]
Now I want to execute all the test cases at once/simultaneously to take advantage of my parallel execution system where I an utilise up to 24 browser instance.
Currently I am iterating over this list and executing as
dotnet test --filter TestCategory=caseid[i]
Here testcase id is also used as #tag.
If there is a way to execute all the tests in the list at once
Try the following syntax:
dotnet test --filter "TestCategory=tc1|TestCategory=tc2|TestCategory=tc3"
If you have large number of tests, you can just generate .sh file for MacOS or .cmd file for windows to run desired batch of tests:
var filter = String.Join("|", caseid.Select(id => $"TestCategory={id}"));
File.WriteAllText("./runbatch.sh", $"dotnet test --filter \"{filter}\"");
and then run tests in terminal:
sh runbatch.sh

how to append the .trx file generated while executing dotnet test command

Per my requirement, I have test case id stored in a list and I am iterating over this list to execute the testcases
for (int i=0;i<=list.size();i++){
dotnet test project.dll --filter Category=list[i] --logger trx;logfilename=testResults[i].trx
}
What is actually happening is we are generating .trx file for each case
because
for (int i=0;i<=list.size();i++){
dotnet test project.dll --filter Category=list[i] --logger "trx;logfilename=testResults.trx
}
is not working as I need
What is Expected some how if we can have a single file for whole execution which have the result for each test from the list

Azure devops Solution build Dotnet

- task: DotNetCoreCLI#2
displayName: Build X (DotNet)
inputs:
command: 'build'
projects: '$(X)'
arguments: '-c "Release" /p:Platform="x64" --output $(Build.ArtifactStagingDirectory)\X'
once I adding the output (--output $(Build.ArtifactStagingDirectory)\X') argument for be able to PublishArtifact after that the build results.
I got error from solution of missing's files in the Build Solution: error MSB3073
and if I remove the output is work good but I have no option to publishArtifact the results
to some 1 have suggestion how can I publish the results to artifact without output? or to solve the output issue
I am not sure if the --output parameter is available. You can alternatively build your solution using your task and add a separate powershell task to copy build directory to your requested folder. For example:
- task: PowerShell#2
displayName: Copy code output to artifactsStagingDirectory
inputs:
targetType: 'inline'
script: 'Move-Item "$(Build.SourcesDirectory)/src/solutionName/bin/Debug" "$(Build.ArtifactStagingDirectory)/X"'

nightwatch - terminate all test suits when a single test fails

Is there a way (e.g. flag) to terminate whole nightwatch tests when a single failed test occur? Or to get at least a status code that the some test failed, within the program?
Thanks!
In your "test_settings" section of your nightwatch.json, add the following entry:
"end_session_on_fail": true
It looks promising.
You can also try creating a global in global.js and set it to true:
"abortOnAssertionFailure: true"
You can run each test suit by different npm script, such as-
"test1": "nightwatch --retries=1 ./src/tests/test1.js",
"test2": "nightwatch --retries=1 ./src/tests/test2.js"
and then you can run this npm script-
"run_tests": "npm run test1 && npm run test2"
is one test case will fail in 'test1' the npm command will fail as well and no other tests case/suits will run.

Continuous Deploy ASP.NET 5 Beta 7 on Azure

I'm trying to deploy my ASP.NET 5 Beta 7 web application to Azure platform using Continuous Deployment on Visual Studio Online.
I've already follow these guides:
https://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5 -> to deploy asp.net 5 web apps
http://www.brandonmartinez.com/2015/09/16/deploying-asp-net-5-beta-7-through-vso/ -> changes to previous guide to deploy asp.net 5 Beta 7 web apps
When I commit and push a changes, the build task triggers correctly but it fails when executing prepublish script of project.json:
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
The error (warning) is:
npm WARN optional dep failed, continuing fsevents#1.0.0
I was able to deploy by enabling Continue on error option in the build definition and only for PublishLocal.ps1 step (that fails).
Visual Studio Online completes (partially) the build and deploy my site to Azure and everything seems to works without problems, but, what is that error? There is a way to fix it?
Here is my PublishLocal.ps1 step (from http://www.brandonmartinez.com/2015/09/16/deploying-asp-net-5-beta-7-through-vso/):
#Requires -Version 3.0
param($vsoProjectName, $projectName, $buildConfiguration, $buildSourcesDirectory)
$VerbosePreference = "continue"
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
$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"
}
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
$dnxRuntimePath = "$($env:USERPROFILE)\.dnx\runtimes\dnx-clr-win-x86.$dnxVersion"
& dnu build "$PSScriptRoot\src\$projectName" --configuration "$buildConfiguration"
& dnu publish "$PSScriptRoot\src\$projectName" --configuration "$buildConfiguration" --out "$buildSourcesDirectory\$vsoProjectName\artifacts\bin\$buildConfiguration\Publish" --runtime "$dnxRuntimePath"
Without seeing your entire build log, it's a little difficult to diagnose. However, my assumption is that NPM is writing WARN messages to stderr. As such, the VSTS build server will see that as an error instead of a warning.
I would recommend either adding --quiet to your NPM scripts, or update your dependency to not throw the WARN. You could also changed the PowerShell script VerbosePreference to SilentlyContinue to see if that stops printing the message as well.

Resources