Skip to main content
Introducing the Automate SDK! Get your entire test suite running on BrowserStack in minutes! Learn More.
No Result Found

Run JUnit 5 Tests in Parallel

Run automated tests on multiple browsers in parallel with JUnit 5 using BrowserStack Automate.

Note: Check out the junit-browserstack repository on GitHub for the code samples used in this section.

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:

  1. Prerequisites
  2. Running your first parallel test

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

  1. 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
    
  2. 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>
    
  3. 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
    
  4. Set your browser-OS combinations in the caps.json file in the junit-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"
             }
           }
         }
       }
     }
    
  5. Run your tests in parallel using the following command:

     mvn test -P parallel
    
Note: Achieve your test coverage and build execution time goals by using our calculator to understand how many parallel sessions you need.

Next steps

After you have successfully run your parallel test on BrowserStack, you might want to do one of the following:

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy Check Circle