The LabKey Server code base includes extensive automated tests. These, combined with hands-on testing, ensure that the software continues to work reliably. There are three major categories of automated tests.
Unit tests exercise a single unit of code, typically contained within a single Java class. They do not assume that they run inside of any particular execution context. They are written using the JUnit test framework. Unit tests can be run directly through IntelliJ by right clicking on the test class or a single test method (identified with an @Test annotation) and selecting Run or Debug. They can also be run through the web application, as described below for integration tests. Unit tests are registered at runtime via the Module.getUnitTests() method.
Integration tests exercise functionality that combines multiple units of code. They do not exercise the end-user interface. Integration tests are implemented using the JUnit test framework, like unit tests. They generally assume that they are running in a full web server execution context, where they have access to database connections and other resources. They can be invoked through the web application by going to http://localhost/labkey/junit/begin.view
or its equivalent URL (based on the server, port, and context path). Integration tests are registered at runtime via the Module.getIntegrationTests() method.
Functional tests exercise the full application functionality, typically from the perspective of an end-user or simulated client application. Most functional tests use the Selenium test framework to drive a web browser in the same way that an end user would interact with LabKey Server. Unlike unit and integration tests, functional tests treat the server as a black-box, and their source code is completely separate from the main server code (though it lives in the same source code repository).
Functional tests are separated into separate test suites, including the Developer Run Tests (DRT), Build Verification Tests (BVT), and Daily suites. The automated build and test system runs these suites at varying frequencies in response to code changes.
Depending on the specific test, Selenium will use different web browsers. Most typically, tests use recent versions of Firefox or Chrome.
To run a functional test on a development machine where LabKey Server is running locally, there are a number of relevant Gradle targets in the server/test directory:
- ./gradlew :server:test:setPassword - Set login to be used by UI tests (inserts into .netrc file in your user home directory, for example, C:\Users\You\_netrc.)
- ./gradlew :server:test:uiTests - Displays a GUI to choose specific tests to run and set options
You can specify various properties to customize test execution. These properties are defined in 'server/test/test.properties' and can be overridden by modifying that file or adding '-Pprop=value' to your command:
- ./gradlew :server:test:uiTests -Ptest=basic - Runs BasicTest
- ./gradlew :server:test:uiTests -Psuite=DRT - Runs the DRTs
- ./gradlew :server:test:uiTests -Psuite=DRT -Pselenium.browser=firefox - Run the DRTs on Firefox
- ./gradlew :server:test:uiTests -Psuite=BVT - Runs the BVTs
- ./gradlew :server:test:uiTests -Ptest=LinePlotTest -Pclean=false - Turn off post-test clean up in order to see the artifacts and sample data created by the test.
: Tests currently run using Selenium 2.53.1 which does not support the latest version of Firefox. You should use Firefox ESR 45
to run LabKey's functional tests (be certain to disable updates or it will update to a newer, incompatible ESR release). You may install multiple versions of Firefox; specify which to use with the selenium.firefox.binary property (e.g. -Pselenium.firefox.binary=/Applications/Firefox45.app/Contents/MacOS/firefox)