4.1. Running JUnit tests

Good software development practice suggests that the test suite be run before committing code. This section describes how you can do that.

4.1.1. Prerequisite: get large test files

Some JUnit tests reference a directory of large test files (GDALargeTestFiles) that are not saved in any of the Git repositories. Note that, despite the name, these files are used in both Dawn and GDA testing.

Developers running JUnit tests at DLS will do not need to do anything to get these files. External developers will need to get a copy of the files (method to be described).

4.1.2. Running JUnit test(s) from the IDE using Run Configurations

4.1.2.1. Run a single JUnit test with an on-the-fly Run Configuration

Note

This method is NOT RECOMMENDED! It does not work for tests that use native libraries or GDALargeTestFiles.

  • In the Package or Navigator view, right-click on the class name.
  • Select Run As ‣ JUnit Test

4.1.2.2. Run all the JUnit tests in a project, using a pre-defined Run Configuration

  • In the Package or Navigator view, right-click on the class name.
  • Select Run As ‣ JUnit-<project-name>

4.1.2.3. Run a single JUnit test in a project, using a pre-defined Run Configuration

sss

4.1.3. Run JUnit tests from the IDE using a pre-defined Run Configuration

Use the Eclipse IDE, running the tests using a JUnit launcher (not available for all projects):

Warning

This method currently doesn’t work for tests that use GDALargeTestFiles. To be fixed soon.

  • Right-click on JUnit-<project-name>.launch at the root of the project directory
  • Select Run As ‣ JUnit-<project-name>

Use the Eclipse IDE, running the tests using an Ant script:

Warning

This method currently doesn’t work for tests that use GDALargeTestFiles. To be fixed soon.

  • Right-click on releng.ant at the root of the project directory
  • Select Run As ‣ Ant Build...
  • On the Targets tab, select junit-tests and Run

OR

Use the Eclipse IDE, running the tests using a JUnit launcher (not available for all projects):

Warning

This method currently doesn’t work for tests that use GDALargeTestFiles. To be fixed soon.

  • Right-click on JUnit-<project-name>.launch at the root of the project directory
  • Select Run As ‣ JUnit-<project-name>

OR

Use the command line and pewma.py (requires Ant version 1.8+):

if [[ "$(uname -n)" == *diamond.ac.uk ]]; then
    module load ant
fi
ant -version

# optionally use tee and grep to save the full console log in a file, but only display a relevant subset on the terminal
pewma.py --workspace=/path/to/workspace --include=name.of.project1[,name.of.project2, ...] junit-tests \
    | tee ~/junit-test-console-log.txt | grep "\(Running\|Tests run\)"

OR

Use the command line and native ant (requires Ant version 1.8+):

if [[ "$(uname -n)" == *diamond.ac.uk ]]; then
    module load ant
fi
ant -version

# optionally use tee and grep to save the full console log in a file, but only display a relevant subset on the terminal
ant -logger org.apache.tools.ant.NoBannerLogger -buildfile /path/to/workspace_git/project_name/releng.ant -DGDALargeTestFilesLocation=/dls_sw/dasc/GDALargeTestFiles/ junit-tests \
    | tee ~/junit-test-console-log.txt | grep "\(Running\|Tests run\)"