Grails functional testing - AtlasOfLivingAustralia/fieldcapture GitHub Wiki

MERIT is using the GEB functional testing framework to run grails functional tests.

To make the tests more useful and to avoid having to update them when ecodata changes, the MERIT functional tests are designed to be run against a running instance of ecodata as the two projects tend to change at the same time.

The functional tests require that you have run npm install so the chromedriver and phantomjs web drivers are installed

To run the tests on your laptop there is a script: runFunctionalTests.sh in the /scripts directory of fieldcapture. This is the same script the travis build uses to execute the functional tests.

This script expects that neither ecodata nor MERIT is currently running.

To run this script locally, pass the path to your local ecodata project as the second argument of the script to prevent the script from cloning ecodata from github.

cd scripts ./runFunctionalTests.sh chrome ../../ecodata

If you have cloned the ecodata project in the same parent folder as the fieldcapture project, the script will use your current version of ecodata. Otherwise, it will clone ecodata and use the dev branch by default.

Executing the tests in this way requires a full start of both ecodata and MERIT so is too slow for developing new tests. To run tests in your IDE environment:

  1. Make sure mongo is running. The tests will use a mongo database called "ecodata-functional-test". This database will be regularly dropped during test runs.
  2. Start ecodata using the grails meritfunctionaltest environment.
    grails run-app -Dgrails.env=meritfunctionaltest
  3. Ensure the scripts in fieldcapture/scripts are executable by the current user `chmod u+x scripts/*.sh'
  4. Start fieldcapture using the grails test environment: grails run-app -Dgrails.server.port.http=8087 -Dgrails.env=test
  5. Run a single test using Intellj or all tests using gradle. Use -Dgev.env=chrome (the default) to run with chrome or -Dgeb.env=chromeHeadless to run the tests in the background, which is useful when running the full test suite. ./gradlew -Dgeb.env=chrome integrationTest

Writing functional tests

  1. Note that when running ecodata and fieldcapture for functional tests, CAS is stubbed using the wiremock library. This means accessing those apps in the browser will not work when the tests aren't running as the tests launch the wiremock proxy.
  2. The FieldcaptureFunctionalTest base class contains a method 'useDataSet(dataSetName)' which will drop the database, then run a mongo script expected to be located at: /test/functional/resources//loadDataSet.js. This script should load any data expected to be in the database at the commencement of the tests.