Skip to main content
Version: 8.6.x

Running Individual Tests

When you debug issues, we recommend executing a specific test through Maven on the command line to save time and for convenience. This topic describes how to use commands to run and remotely debug single unit tests or integration tests.

note

All commands in the examples open remote debugging on port 8000.

Surefire Unit Tests​

The Maven Surefire plugin is used to run unit tests of an application. For more information, see the Maven Surefire Plugin documentation.

Running a single test​

To run a single test using the Maven Surefire plugin, use the following command:

mvn test -Dtest=<TEST_CLASS_NAME#TEST_METHOD_NAME>

Debugging a single test​

To debug a single test using the Maven Surefire plugin, use the following command:

mvn test -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" -Dtest=<TEST_CLASS_NAME#TEST_METHOD_NAME>

Failsafe Integration Tests​

The Maven Failsafe plugin is used to run integration tests. For more information, see the Maven Failsafe Plugin documentation.

Running a single integration test​

To run a single Maven Failsafe plugin integration test, use the following command:

mvn verify -Dit.test=<TEST_CLASS_NAME#TEST_METHOD_NAME>

Debugging a single integration test​

To debug a single Maven Failsafe plugin integration test, use the following command:

mvn verify -Dmaven.failsafe.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" -Dit.test=<TEST_CLASS_NAME#TEST_METHOD_NAME>

Failsafe Cucumber Tests​

The Maven Failsafe plugin also supports using Cucumber.

Running a single Cucumber test​

To run a single Cucumber test, use the following command:

mvn verify -Dcucumber.options="src/test/cucumber/com/elasticpath/cucumber/<FEATURE_FILENAME>"

Debugging a single Cucumber test​

To debug a single Cucumber test, use the following command:

mvn verify -Dmaven.failsafe.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" -Dcucumber.options="src/test/cucumber/com/elasticpath/cucumber/<FEATURE_FILENAME>"

Failsafe Selenium Tests​

The Maven Failsafe plugin also supports using Selenium.

  1. Start the Selenium standalone Chrome docker image:

    docker run -d \
    -p 4444:4444 \
    -p 7900:7900 \
    -e SCREEN_WIDTH=1920 \
    -e SCREEN_HEIGHT=1080 \
    -e SCREEN_DEPTH=24 \
    --shm-size=2g \
    selenium/standalone-chrome:latest
    note

    On a Mac M1 processor, replace selenium/standalone-chrome:latest with seleniarm/standalone-chromium:latest in the command above.

  2. Start the following locally:

    • ActiveMQ
    • Cortex
    • Search Server
    • Batch Server
    • Integration Server
    • Commerce Manager
    note

    Use the following command to start Commerce Manager:

    mvn clean tomcat8:run-war -Dorg.eclipse.rap.rwt.enableUITests=true

Running a single Selenium test​

To run a single Selenium test, change to your extensions/cm/ext-cm-modules/system-tests/selenium folder and use the following command:

mvn verify -Premote \
-Dselenium.session.browser=remote_chrome \
-Dremote.web.driver.url=http://localhost:4444/wd/hub \
-Dselenium.session.baseurl=http://host.docker.internal:8081/cm \
-Dep.export.cm.host=host.docker.internal \
-Dep.import.cm.host=host.docker.internal \
-Dexport.db.connection.host=localhost \
-Dexport.import.db.schemaname=<DB_SCHEMA> \
-Dexport.import.db.connection.username=<DB_USERNAME> \
-Dexport.import.db.connection.password=<DB_PASSWORD> \
-Dsearch.host.url=http://localhost:8082/searchserver \
-Dcucumber.options="src/test/resources/com.elasticpath.cucumber/<FEATURE_FILENAME>"
note

Make sure to replace the <DB_SCHEMA>, <DB_USERNAME>, and <DB_PASSWORD> placeholders in the command above.

Debugging a single Selenium test​

To debug a single Selenium test, change to your extensions/cm/ext-cm-modules/system-tests/selenium folder and use the following command:

mvn verify -Premote \
-Dselenium.session.browser=remote_chrome \
-Dremote.web.driver.url=http://localhost:4444/wd/hub \
-Dselenium.session.baseurl=http://host.docker.internal:8081/cm \
-Dep.export.cm.host=host.docker.internal \
-Dep.import.cm.host=host.docker.internal \
-Dexport.db.connection.host=localhost \
-Dexport.import.db.schemaname=<DB_SCHEMA> \
-Dexport.import.db.connection.username=<DB_USERNAME> \
-Dexport.import.db.connection.password=<DB_PASSWORD> \
-Dsearch.host.url=http://localhost:8082/searchserver \
-Dmaven.failsafe.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" \
-Dcucumber.options="src/test/resources/com.elasticpath.cucumber/<FEATURE_FILENAME>"
note

Make sure to replace the <DB_SCHEMA>, <DB_USERNAME>, and <DB_PASSWORD> placeholders in the command above.

Running Selenium tests by tag​

To run all Selenium scenarios with a specific Cucumber tag, replace the -Dcucumber.options argument in the command above with a tag expression. For example, to run the smoke tests:

-Dcucumber.options="--tags @smokeTest"

You can replace @smokeTest with any tag defined in the feature files, including tags that you add to your own scenarios.

Running Selenium tests in parallel​

By default, Selenium tests run in a single fork. The Selenium module contains a separate test runner class for each functional area, and failsafe.fork.count specifies how many runners execute at the same time. To run tests in parallel, add the following argument to the command above:

-Dfailsafe.fork.count=<FORK_COUNT>
note

Each fork opens its own browser session. By default, the Selenium standalone Chrome container accepts one session at a time. To allow more sessions, add -e SE_NODE_MAX_SESSIONS=<FORK_COUNT> to the docker run command.

View the running test​

To see what is happening inside the container, connect to http://localhost:7900/?autoconnect=1&resize=scale&password=secret.