Running all test with PHPUnit in Symfony - unit-testing

I'm using PHPUnit 5.4.8 and Symfony 2.3
I have all my bundles with unit tests and I would like to run all those tests, with coverage in html. I tried with the command
phpunit -c app --no-globals-backup --coverage-html ~/coverage/ src/*Bundles/Tests/Unit
But it just doesn't work.
This is my test suite in phpunit.xml.dist
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests/Unit</directory>
</testsuite>
</testsuites>

I figure out how to do it, first the name of the test suite can't have blank spaces, so phpunit.xml.dist file is this now:
<testsuites>
<testsuite name="Project">
<directory>../src/*/*Bundle/Tests/Unit</directory>
</testsuite>
</testsuites>
And you run the test suite with command:
phpunit -c app --no-globals-backup --coverage-html ~/coverage/ --testsuite Project

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!

Testing - How to split up pre-commit unit tests and CI end-to-end tests

Scenario
I'm working on an app that has fast unit/functional jest tests along with slower end-to-end jest-puppeteer tests. I would like to split those up so that I can run the faster tests as part of a git pre-commit hook and leave the end-to-end tests to be run on CI after the code is eventually pushed to origin.
Question
How can I define specific tests to run at pre-commit? Specifically via regex similar to jest moduleNameMapper eg <rootDir>/__tests__/[a-z]+\.unit\.test\.js
Best idea so far:
in package.json add test:pre which uses bash find . -regex with bash for do to run desired "pre commit" tests
I've added
"test:pre": "PRE=1 npm test -- test/pre-*test.js"
# everything after -- is a kind of regex filter for matching file names
to my package.json scripts and in my jest-puppeteer global-setup.js I'm using
if(+process.env.PRE) return;
before all the puppeteer extras are started. So now I can
$ npm run test:pre
and violá

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.

Create job for every testsuite using job dsl

I'm using TestNG, Jenkins, and the job-dsl-plugin.
I have a lot of TestNG XML testsuites for the tests in my project. What I want is a script that will go through each of these suites and create a job for them.
My test suites are formatted like this:
<suite name="Name of Suite">
<test name="Name of Test">
<packages>
<package name="package.to.test.*"/>
</packages>
</test>
</suite>
So the job DSL script would have to recursively go through each of the tests in my testsuites directory, grab and parse the XML of these files, and then create a job for each one of them.
Visit repo
Recursively read every XML file in testsuites directory
Grab the name of the suite -> name of Jenkins job
Grab the path to this testsuite -> -Dtestngfile=<path>
Create a job for each of these

run all zend framework2 unit tests

I'm trying to get a project build setup in Jenkins for Zend Framework 2, I want to run all the unit tests for each of the modules I am writing - but I'm a lil unclear how to do this?
Each module has its own 'test' directory and I can run each modules test suite just fine. Do I have to write some script to find all custom modules and run their tests? Does anyone have a good example how to do this?
First, get the test to run together
I would try writing a new phpunit config file, say all.xml, giving the details of the different test files.
<phpunit>
<testsuite name="Module1">
<directory>./module1</directory>
</testsuite>
<testsuite name="Module2">
<directory>./module2</directory>
</testsuite>
<testsuite name="Module2">
<directory>./module3</directory>
</testsuite>
</phpunit>
Test that this runs ok on the command line
$ phpunit -c all.xml
Add to Jenkins
Just add this into you Jenkins config. Here is an example if you use an Ant xml file:
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true">
<arg line=" -c tests/all.xml" />
</exec>
</target>