Testing - AtlasOfLivingAustralia/profile-hub GitHub Wiki
The grails/groovy code is tested using the Spock framework. Tests live in the src/tests/groovy/ and src/integration-test/groovy directories.
The UI layer of the profile hub is written in AngularJS. We use the Jasmine test framework and the Karma test runner to test the Angular code. This guide tells how to install and run the tests on Mac OS (tested with Yosemite).
- Navigate to the root directory of the profile-hub project
- Execute the following:
brew install node.jsnpm install karmanpm install karma-jasmine karma-chrome-launcher --save-devnpm install -g karma-clinpm install karma-coveragenpm install karma-ng-html2js-preprocessor --save-dev
- Install other optional browser launchers:
npm install karma-firefox-launchernpm install karma-safari-launchernpm install karma-ie-launcher- Update the
browsers: ['Chrome']property in karma.conf.js to add additional browsers to test against.
- The source repository contains a karma.conf.js file: this is configures the Karma test runner
- (Optional) Install the IntelliJ Karma test runner:
- Preferences -> Plugins -> Search for Karma -> Install (at the time of writing there was only 1 matching plugin)
- Create a run configuration:
- Run -> Edit Configurations -> New -> Karma
- Give it a name
- Select the karma.conf.js file from the root of the project directory as the Configuration File
- The other default values are fine.
The karma.conf.js file contains a list of all Javascript resources required for testing in the files list. If you create a new file, you must update the karma.conf.js file or your tests won't work.
// list of files / patterns to load in the browser
files: [
'grails-app/assets/thirdparty/angular-1.3.13.min.js',
'grails-app/assets/thirdparty/angular-mocks-1.3.13.js',
'grails-app/assets/thirdparty/ui-bootstrap-tpls-0.12.0.js',
'grails-app/assets/javascripts/profileEditor/profiles.js',
'grails-app/assets/javascripts/profileEditor/utils/*.js',
'grails-app/assets/javascripts/profileEditor/services/*.js',
'grails-app/assets/javascripts/profileEditor/controllers/*.js',
'grails-app/assets/javascripts/profileEditor/templates/*.tpl.htm',
'grails-app/assets/javascripts/profileEditor/directives/*.js',
'src/test/js/specs/MockConfigModule.js',
'src/test/js/specs/**/*.js'],
The order is important!
Jasmine tests live in the src/tests/js/specs/ directory. Update existing files or add new ones as necessary.
You can see a code coverage report for the javascript files by following these steps:
- Command Line
- Run
karma start - Open
coverage/<browser>/index.html
- Run
- IntelliJ
- Run the karma configuration using the
Run 'karma' with Coverageoption (the 3rd toolbar button after the run dropdown). - Open
coverage/<browser>/index.html - IntelliJ will also annotate the filenames in the project explorer with a percentage of lines covered.
- Run the karma configuration using the