Run JUnit 5 Tests in Parallel
Run automated tests on multiple browsers in parallel with JUnit 5 using BrowserStack Automate.
Introduction
On BrowserStack, you can run multiple JUnit 5 tests at the same time across various browser, device, and OS combinations. This is called Parallel Testing. Parallel Testing gives you the same benefits as running a multi-threaded application.
With Parallel Testing, you can run the same test on different browser/device combinations, namely cross-browser testing, or run different tests on the same or different browser/device combinations. Parallel Testing helps you reduce the run time of your test suite, resulting in faster build times and faster releases.
In this guide, you will learn about:
Prerequisites
If you have already run your first test, you can skip the prerequisites.
- BrowserStack Username and Access key, which you can find in your account settings. If you have not created an account yet, you can sign up for a Free Trial or purchase a plan.
-
Maven is installed on your machine, Maven environment variables are set, and Maven bin is added to system path,
$PATH
. Check our the official website to download the latest version of Maven. - Git installed on your machine.
Run your first parallel test
-
Clone the junit-browserstack sample repo on GitHub using the following command:
git clone -b selenium-4 https://github.com/browserstack/junit-browserstack.git cd junit-browserstack/junit-5
-
Set the following configuration parameters that enable parallel execution using JUnit 5 in the
pom.xml
file.<properties> <configurationParameters> junit.jupiter.execution.parallel.enabled = true junit.jupiter.execution.parallel.mode.default = concurrent junit.jupiter.execution.parallel.config.strategy=fixed junit.jupiter.execution.parallel.config.fixed.parallelism=<parallel-count-value> </configurationParameters> </properties>
-
Open the cloned project in the IDE of your choice and install the required dependencies by running the following command in your command line:
mvn clean install
-
Set your browser-OS combinations in the
caps.json
file in thejunit-5/src/test/resources/
directory as follows:caps.json{ "tests":{ "parallel": { "common_caps": { "name": "parallel-test", "build": "junit5-browserstack", "browserstack.console": "verbose", "browserstack.debug": "true" }, "platform":{ "chrome": { "browser": "chrome", "browser_version": "latest-1", "os": "Windows", "os_version": "10" }, "safari": { "browser": "safari", "browser_version": "latest", "os": "OS X", "os_version": "Big Sur" }, "firefox": { "browser": "firefox", "browser_version": "latest-2", "os": "OS X", "os_version": "Monterey" }, "edge": { "browser": "edge", "browser_version": "latest", "os": "Windows", "os_version": "11" }, "android": { "device": "Samsung Galaxy S21", "os_version": "11.0" }, "ios": { "device": "iPhone 12 Mini", "os_version": "14" } } } } }
-
Run your tests in parallel using the following command:
mvn test -P parallel
Next steps
After you have successfully run your parallel test on BrowserStack, you might want to do one of the following:
- Migrate existing tests to BrowserStack
- Test on private websites that are hosted on your internal networks
- Select browsers and devices where you want to test
- Set up your CI/CD: Jenkins, Bamboo , TeamCity, Azure , CircleCI, BitBucket , TravisCI, GitHub Actions
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!