run all zend framework2 unit tests - unit-testing

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>

Related

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á

Cannot view code coverage on angular-cli new project

I'm trying to figure out how to get code coverage working with #angular/cli but so far i'm not having much luck.
I started a new project using angular CLI. Basically all i did was ng new test-coverage and once everything was installed in my new project folder, I did a ng test --code-coverage. The tests were run successfully but nothing resembling code coverage was displayed in the browser.
Am I missing some dependencies or something else? Any help will be appreciated.
EDIT:
R. Richards and Rachid Oussanaa were right, the file does get generated and I can access it by opening the index.html.
Now i'm wondering, is there a way I could integrate that into a node command so that the file opens right after the tests are run?
here's what you can do:
install opn-cli which is a cli for the popular opn package which is a cross-platform tool used to open files in their default apps.
npm install -D opn-cli -D to install as dev dependency.
in package.json add a script under scripts as follows
"scripts": {
...
"test-coverage": "ng test --code-coverage --single-run && opn ./coverage/index.html"
}
now run npm run test-coverage
this will run the script we defined. here is an explanation of that script:
ng test --code-coverage --single-run will run tests, with coverage, only ONCE, hence --single-run
&& basically executes the second command if the first succeeds
opn ./coverage/index.html will open the file regardless of platform.

Running all test with PHPUnit in Symfony

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

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