Generate xUnit test results in .json format - dotnet-test

Currently, I'm running a set of xUnit test using the following command:
dotnet test --filter TestType=$testType --logger trx
Is there a way to generate results in json format? Something like --logger json?
Thank you.

Related

Publish code coverage not finding coverage file in Azure DevOps

I'm using Node 14.x and Jest 26.x. There is a npm test script in package.json file which contains the following:
cross-env NODE_ENV=test jest --coverage --forceExit
When I run it locally, it generates the code coverage report in ./coverage directory. The contents of ./coverage directory is as follows:
lcov-report (folder)
clover.xml
coverage-final.json
lcov.info
It looks like clover.xml contains code coverage report. There are more details which can be found in lcov-report folder.
I've setup the Azure DevOps pipeline as follows for code coverage:
...
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '**/junit.xml'
# Publish code coverage results
# Publish Cobertura or JaCoCo code coverage results from a build
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/clover.xml'
After running the pipeline, Azure DevOps doesn't seem to find the cover.xml file. I get the following error:
##[debug]Result: true
##[debug]Report directory: /home/vsts/work/_temp/cchtml
Reading code coverage summary from '/home/vsts/work/1/s/coverage/clover.xml'
##[warning]No coverage data found. Check the build errors/warnings for more details.
##[debug]Processed: ##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=/home/vsts/work/1/s/coverage/clover.xml;reportdirectory=/home/vsts/work/_temp/cchtml;]
I also tried the following options for summaryFileLocation but all resulted in same error.
'**/coverage/clover.xml'
'$(System.DefaultWorkingDirectory)/**/coverage/clover.xml'
I understand that the format of clover.xml may not be the same as Cobertura or JaCoCo, but at least Azure should be able to locate the file.
What I'm missing?
I've found a way accidentally.
It looks like Jest can generate cobertula coverage report. It needs to be added in Jest configuration. I've added the following in jest.config.js:
coverageReporters: ['text', 'text-summary', 'clover', 'cobertura']
Jest generated the cobertura coverage file in:
./coverage/cobertura-coverage.xml
Next I modified Azure pipeline file as follows:
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
After this changes, when I run the pipeline, Azure DevOps can find the file and show coverage report!

How to install Cobertura in azure Devops?

I have a .net core whith CI in Azure devops.
After successfully running my unit tests, I would like to generate and display code coverage using ReportGenerator, based on this article:
https://www.meziantou.net/computing-code-coverage-for-a-dotnet-core-project-with-azure-devops-and-coverlet.htm
Part of the YAML:
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines;Cobertura
displayName: Create Code coverage report
This gives me the folling error:
...line 2: Cobertura: command not found
By removing the Cobertura from reporttypes, there are no errors, but then there are no report to be shown.
How can I install or enable Cobertura?
By removing HtmlInline_AzurePipelines from reporttypes, it worked
This way you are skipping a parameter option. Accordingly to the documentation, you can try to wrap that option with " like in the following:
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
displayName: Create Code coverage report
This should probably work as well without skipping it.

Jenkins build success but failed on Unit test

I am having issue resolving Jenkins unit test fail with following error: "testException = java.lang.AssertionError: expected:<> but was:<>" Jenkins build was success with Unit test fail. Please help.
Can you give some more details about your jenkins job?
I believe you need to publish the junit test results to alter the build status.
E.g. If you are using a jenkinsfile for your configuration
// publish JUnit results to Jenkins
step([$class: 'JUnitResultArchiver', testResults: '**/build/test-results/*.xml'])
If you are using the ui configuration for the job there is a field where you can configure this.

Jenkins tests reports analyzer integration with catch

I've recently started working with Jenkins to automatically build my c++ project and run my tests (I'm using catch.cpp).
I wanted some sort of a table of test run time and status and that led me to the "Test Results Analyzer" Plugin for Jenkins.
I have my builds run like this:
And you can see they actually run in the console output:
finally, my test results analyzer plugin shows nothing:
It looks like the plugin does not recognize that these are my tests. Which is reasonable since I've only told jenkins to execute these commands and i don't think it's smart enough to understand these are the tests to report. But i could not find how to tell "Test Reports Analyzer" what are the tests it needs to report.
My question is how do i get a table of tests like in the Plugins webpage:
Tests Reports Analyzer
Solution:
Jenkins needs a Junit format xml file of the test results.
specifically, in Catch.cpp this is achieved by the "-r junit" command line option.
after this i needed to configure jenkins to "Publish JUnit test result report" post-build action and git it a path to the output xml file i create with my "make test" command.
Solution provided by OP:
Jenkins needs a Junit format xml file of the test results.
specifically, in Catch.cpp this is achieved by the "-r junit" command line option.
after this i needed to configure jenkins to "Publish JUnit test result report" post-build action and git it a path to the output xml file i create with my "make test" command.

Running the Unit test cases in solr using ant

I am trying to run my test cases in solr using ant. Below is the ant command I am using:
ant test –Dtestcase=<test case name> test -Dtests.leaveTemporary=true
Now I have my own customized solrconfig & schema, so running above command builds the project again & overrites my customized solrconfig & schema.
Kindly help me with this.
You can use the method:
initCore(String config, String schema, String solrHome) of class SolrTestCaseJ4.java in your TestCase and pass the path of your customized schema and config as your solrHome(typical format: solr\collection1\conf).