I am running test using dotnet test (dotnet SDK version: 6.0.402)
the command looks like this
"C:/Program Files/dotnet/dotnet.exe" test "D:\MyRepo\MyProj.csproj" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:SolutionDir=D:\MyRepo --configuration Release --logger "trx;logfilename=MyProj.UnitTest.csproj.trx" --no-build --no-restore --results-directory="testOutput"
I am not providing a .runsettings file at the moment.
Now, I'd like the execution to bypass the behaviour of ExcludeFromCoverageAttribute. In other words, I want cobertura to consider all code coverable, even that annotated with ExcludeFromCoverageAttribute
I've tried passing my own .runsettings file with a datacollector that didn't exclude such attribute, but it doesn't seem to be making a difference
Is there a way to achieve what I am trying to do?
Related
I am trying to replicate the following Azure pipeline using the CLI dotnet command:
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
So far, I can make the project build, but getting a zip file out of it seems problematic - passing the inputs zipAfterPublish etc appears impossible to pass, although, there is some scattered documentation suggesting these can be passed with -p:"optiona=x;optionb=y" or /p:"optiona=x;optionb=y". I can find no definitive documentation on this.
This is what I have - the build part works, the $PWD/out directory is populated with many files but nothing is zipped:
dotnet publish --configuration Release --output $PWD/out /p:"zipAfterPublish=true;publishWebProjects=true"
I'm guessing this is around how to pass the inputs ( https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops ) correctly to the command.
I am trying to replicate the following Azure pipeline using the CLI
dotnet command:
1.The zipAfterPublish is one option available only in Dotnet Publish task. If you check the log of dotnet publish task, you'll find it doesn't pass any property like zipAfterPublish to the command:
Since only the msbuild property can be passed in this way: /p:xxx=xxx. The zipAfterPublish won't work in command-line as it's not msbuild property, that option is not supported in dotnet cli, only available in Azure Devops Dotnet Publish task.
2.Normally if we want to publish one .net core web project and zip it after publish using dotnet cli locally, we can use command like:
dotnet publish xx.csproj /nologo /p:PublishProfile=xxx /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform=xxx /p:configuration=xxx /p:DesktopBuildPackageLocation=SomePath\xxx.zip
Or
dotnet build xxx.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\Some\Path\package" /p:OutDir="C:\Some\Path\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\Some\Path\package\package.zip"
Which is described in this issue.
Above commands can work in windows to generate a xx.zip folder.
However:
It seems that you're in linux environment, please check this document. If you want to zip the publish folder(generate a package), the dotnet build/publish will call msdeploy.exe to do this job, but since MSDeploy lacks cross-platform support, the following MSDeploy options are supported only on Windows. So dotnet cli command is not supported to generate zip after publish in linux environment... What you want is not supported for now in Linux.
Possible workaround:
Since we can use dotnet publish to publish the project to one folder(Folder works cross-platform), we can call another zip command after dotnet publish to zip it ourselves.
Hope my answer helps to resolve your puzzle :)
I'm struggling to make work a simple CI/CD pipeline with dependencies between stages. This is my .gitlab-ci.yml file:
image: gcc
stages:
- build
- test
build_app:
stage: build
script:
- make
- make install
test_app:
stage: test
script:
- run app ...
dependencies:
- build_app
So the build stage will compile the application and install it under /usr/local/bin/. The above example will fail because the test stage does not find the executable, even when it is states as dependent on the build step (it seems it is not attached by default).
If I define /usr/local/bin/app as an artifact it will also fail, because these must be relative and child of $CI_PROJECT_DIR (reference).
So I'm now trying to do some modifications on it but I feel I do not really understand what is going on there. I finally tried to attach the file compiled (APP) in the repository directory as an artifact (without using make install), and calling that binary for testing (eg. ./APP instead of APP). This way, it works, but I feel like I had to renounce to the make install instruction, and also that there is probably a much better and straightforward way to implement this.
Is there a recommended way to perform this task?
cache won't work either. It is restricted (though not documented) to the same limitations as artifacts.
These are both security measures since it would otherwise provide access to the entire filesystem the gitlab-ci-runner is installed.
The solution would be to install the binary in a path relative to your build directory instead of /usr/local/bin/app and use artifacts.
In azure devops build pipeline, I am having the below stages.
Prepare analysis on sonar cloud
dotnet restore
dotnet build
dotnet test
dontnet publish
copy test files .. this for copying (*.trx *.xml) to respective directory.
Run code analysis
Publish quality gate result.
here my pipeline runs successfully with the tests but its not giving code coverage. code coverage showing 0.00%
*.trx file is copying on the required path & I have also tried with the default path of trx file but its giving below message in logs.
ERROR MESSAGE
Post-processing started.
00:23:49.775 Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders.
00:23:49.995 Did not find any binary coverage files in the expected location.
00:23:49.995 Falling back on locating coverage files in the agent temp directory.
00:23:49.995 Searching for coverage files in D:\a\_temp
00:23:49.995 No coverage files found in the agent temp directory.
WARNING: The following projects do not have a valid ProjectGuid and were
not built using a valid solution (.sln) thus will be skipped from
analysis...
D:\a\1\s\Rost.API.Tests\Rost.API.Tests.csproj
I expect the code coverage in the pipeline, currently code coverage showing 0.00%.
May i confirm several questions with you?
Did you add --collect "Code coverage" option to the command line arguments?
Code coverage can be collected by adding --collect "Code coverage"
option to the command line arguments. This is currently only available
on the Windows platform.
If run the test command on local, did the code coverage show correctly?
BTW, SonarQube requires a valid Project GUID but Core projects dont actually use this.It is recommended to add the ProjectGUID in the test project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- SonarQube requires a valid Project GUID but Core projects dont actually use this -->
<ProjectGuid>{9C99E491-F56E-4515-9F0B-D72A5207DB13}</ProjectGuid>
</PropertyGroup>
</Project>
Has anyone attempted to integrate jest unit tests with TFS 2015? I tried to use Chutzpah Test Adapter (https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC=VSIDE) however it's not able to recognize jest. I receive below error:
Can't find variable Jest
When I run the unit tests through "npm test" I get the results. However to integrate with TFS 2015 I need a test runner which can run Jest unit test so that I can run the unit tests in conjunction with vstest.console.exe which the TFS 2015 provides so it can manage build results and publish results in the build summary report.
Any help would be appreciated!!
Any test runner which can run tests using below command should work (considering VS 2015 installed on the system):
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "\test.js" /UseVsixExtensions:true
Extending on Merlin's answer, here is how I've implemented publishing jest test results AND code coverage to TFS2015 vNext builds (I am using create-react-app boilerplate):
First install required packages on the Server you are running your Agent on:
npm install -g jest-json-to-tap
npm install -g tap-xunit
configure jest to output json, by changing in package.json the "test" task to:
"test": "react-scripts test --env=jsdom --json",
configure jest options in package.json:
"jest": { "coverageReporters": ["cobertura"] }
created a vNext build (TFS2015v4) with the following tasks:
a. "npm" task, command=run, arguments=test -- --coverage | jest-json-to-tap | tap-xunit > TEST-result.xml
b. "publish test results" task, format=JUnit
c. "public code coverage results" task, code coverage tool=Cobertura, Summary file=$(Build.Repository.LocalPath)\coverage\cobertura-coverage.xml
make sure your build's "Variables" include setting the environment variable "CI"="true"
NOTES:
- test results will not include times nor assemblies - something to extend for the future...
Voila'! Running this build will correctly publish the test results and code coverage stats, as well as report artifacts.
I'm not sure about jest, but there's a neat npm package that can convert TAP based results to xUnit XMLformat, and then you can publish that to TFS.
Take a look at tap-xunit.
I had a build environment where javascript testing was done by various tools and frameworks (AVA, Mocha, Jasmine etc). We decided to export them all to TAP format, run them throw tap-xunit and then publish to TFS.
Basically, you need something like this:
npm test | tap-xunit > results.xml
You pipe the results to tap-xunit and save them to an XML. This gives you an XML formatted as xUnit that you can publish to TFS. If you're running TFS 2015, I strongly recommend going with vNext builds, a lot easier to get these running. Check the "Publish Test Results" build step.
If you are running with XAML build, this link will help you: Javascript Unit Tests on Team Foundation Service with Chutzpah
If you are running with vNext build, please try the detail steps mentioned with Jasmine.JS test(also a kind of JavaScript test ) in this blog.
I have my .gitlab-ci.yml file set up in the typical three stages: test, build, deploy. During the build stage, I run a command that compiles my project and puts it in a tarball. The build stage appears to execute successfully because it moves on to the deploy stage, but the deploy stage then says it can't find the tarball. Is it in another directory? What happened to it? Thanks.
For each test gitlab-ci clean the build folder, therefore the output files of the build stage are not available in the deploy stage.
You need to rebuild your project also in the deploy stage.
The "stages" are only useful to order your tests, i.e. avoid to try to do a deploy test if a build test failed.
EDIT:
Since Gitlab 8.6, it is possible using dependencies feature
I was surprised to see the same behaviour (on GitLab 8.4).
I use cmake to create makefiles, then make to build, and then make test to run the test. I run all these in a build/ directory.
I don't want to repeat myself and identify easily which steps are failing. As such, I've created different gitlab-ci stages: cmake, make, test, etc. I then tell gitlab-ci to keep the build directory using the cache option:
cache:
key: "$CI_BUILD_REF_NAME"
untracked: true
paths:
- build/
I think that the key option will keep the same build directory for all stages acting on the same branch. See the gitlab-ci doc here: http://doc.gitlab.com/ce/ci/yaml/README.html#cache
EDIT: Don't use the cache for this! GitLab implemented reusable artifacts between stages in 8.4: https://gitlab.com/gitlab-org/gitlab-ce/issues/3423
The CI runners will have to be adapted to support this. See: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/336