Running Automated Tests

2024-04-26

Overview

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

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

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

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 Ant targets in the server/test directory:

  • ant usage - Describes the different targets available, and their command-line parameters
  • ant drt - Runs the DRTs
  • ant bvt - Runs the BVTs
  • ant drt -Dselenium.browser=firefox - Run the DRTs on Firefox
  • ant test - Displays a UI to choose specific tests to run and set options
  • ant test -Dtest=basic - Runs BasicTest
WARNING: Selenium does not support the latest version of Firefox. You should use Firefox ESR 45 to run LabKey's functional tests.