Skip to content

JUnit5/Gradle Tests

These tests are supported in the following workspace types:

  • Spring 6 [Gradle]
  • Spring 6 [Gradle, No default server]

Available test-related dependencies include:

  • org.junit.platform:junit-platform-launcher
  • org.springframework.boot:spring-boot-starter-test

Test Structure

Execution

Folder Structure

Junit Gradle tests require a test directory to be configured in Author under "Java JUnit Gradle Test Test file directory". It must be at least in the same top-level package as the class you want to test, for example:

src/test/java/com

JUnit Gradle tests will be added to <specified directory in Author>/CurriculumTest.java when run. This file is overwritten with the checkpoint test every time checkpoints are run. The test directory does not need to be added to the default workspace, the LE will create this directory if it does not exist when tests are run.

If learners are to run commands from the terminal and you do not want them to trigger tests, make sure to set the "Prevent Checkpoint Run" toggle on the terminal component in Author.

Test Compilation

Compilation errors in the test file or workspace code should be parsed & displayed in the LE to learners prior to tests running. If you see unexpected behavior here, please report to #learning-platform-support.

Test File Structure

All tests should be correctly scoped to the same package (e.g. com.codecademy.ccapplication) as the class that you want to test package and have a single CurriculumTest class.

If there is no CurriculumTest class, your test will not run as expected!

package com.codecademy.ccapplication;

class CurriculumTest {
  @Test
  @DisplayName("I'm a test!")
  void testSomething() {
    //Test
  }
}

Test Troubleshooting

If you are not seeing the results you'd expect from running checkpoints normally via running code, you can manually run a test command from a terminal component. Save/run code to load the proper checkpoint file into the workspace (or manually edit the test file in the workspace) and run the test in the terminal with:

gradle test --tests "*CurriculumTest" --info

If you see failing tests in the raw test output but the LE is handling it differently, please document and file a report with engineering in #learning-platform-support. JUnit/Gradle test reporting can have subtle output formatting differences, and test parsers may need to be updated.

Example Tests

Two example tests can be found in the first checkpoint of this exercise.

Other Guidelines

  • Actual code (real variable names, language syntax, etc. ) in feedback messages should be code-ticked (`)
  • JUnit Gradle tests should follow Test standards.