1. Clone cstools
a. Create folder where project will be located, e.g. c:/cstools_unit
b. Open cmd and go to the folder c:/cstools_unit
c. Clone cstools repository e.g."git clone https://firstname.lastname@example.org/gsamaritan/cstools.git"
2. Install required tools
a) NodeJs. Find latest nodejs here https://nodejs.org/en/. Add “C:\Users\[USER]\AppData\Roaming\npm;C:\Program Files\nodejs\;” to the PATH variable, where [USER] your current user in windows system
b) Karma. In the cstools project folder open test_suites/karma/install/ folder and execute karma-install.cmd
c) Jasmine. In the cstools project folder open test_suites/karma/install/ folder and execute jasmine-install.cmd
a) Open cstools project folder
b) Open test_suites/karma folder
c) Open karma.conf.js
files – files that should be loaded for testing and coverage statistic
exclude – files that should not be loaded for testing and coverage report
preprocessors – list of files from b. that should be included for coverage report
4. Create unit test
a) testcases folder – this folder created for unit tests, if you want to add new test please add new file. Please use testcases\sDs.test.js as example (please see comments in file for better understanding)
b) All files that located in this folder will be executed automatically
5. Run tests on local computer
a. Open cmd and chdir c:\cstools_unit\test_suites\karma
b. Run via type "karma start" and press enter
c. Find results in the c:\results\ folder
The c:\results\unit folder contains testing results
The c:\results\coverage folder contains results of coverage statistic
6. Add to Continuous Integration
a. After checking test locally push it to git.
b. If conf.js file has been changed, please push only files,exclude,preprocessors variables changes.
c. Verify all works as expected, via check your test executed successfully via click over "Jasmine Report" or "Coverage Report" links on the Jenkins page http://jenkins.samaritan.com:8080/job/RS15%20deploy%20and%20test%20CStoolsDev/
Configuring Tests to Run in PhpStorm:
You can integrate your test runs and code coverage into PhpStorm. The steps are listed below:
- Follow the link below to install the Karma plugin and the karma-jasmine package.
Note: you will be using Karma NOT JSTestDriver
Note: Because the above link is a few years old, installing the karma-jasmine package is found in a different place. See image below:
- Once you have your testing setup correctly you can create a karma.conf file for any project you want to create unit tests for.