Skip to main content
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Test Reporting & Analytics on JUnit4

Quick start guide to integrate BrowserStack Test Reporting & Analytics with JUnit4

Prerequisites

  • You have a JUnit4 test suite.
  • Maven is installed on your machine, its environment variables are set, and its bin is added to system path, $PATH.
  • You may run your tests on BrowserStack Automate or even on any other cloud provider or even locally.
  • Your tests can be unit / integration / functional or of any nature.
  • Cucumber-Java v5+ (for Cucumber-JUnit4), Java v8+, Selenium v2.5+ (JSON Wire / W3C).

Integrate with Test Reporting & Analytics

You can use BrowserStack Test Reporting & Analytics both when you’re using BrowserStack’s devices and browsers to run your functional end-to-end tests and also if you’re running tests locally on your laptop/CI system or even when you’re using some other cloud provider.

Not only that, Test Reporting & Analytics is agnostic to the type of testing and hence you could also integrate it with your unit or integration test suite written using JUnit4.

Choose JUnit4 or Cucumber-JUnit4 depending on your test setup.

Please select your setup below to get started with an awesome debugging experience with Test Reporting & Analytics:

To start using BrowserStack Test Reporting & Analytics with your existing setup of Junit4 tests running on BrowserStack Automate, you’d need to integrate with browserstack-java-sdk (if not already done). Follow one of the methods below to integrate the SDK and start using Test Reporting & Analytics:

If you’re an existing browserstack-java-sdk user, you can skip the steps below. However, ensure that you’ve specified static names (names should not change across build runs) for projectName and buildName in the browserstack.yml file in your project. Also, restrict the characters in your projectName and buildName to alphanumeric characters (A-Z, a-z, 0-9), underscores (_), colons (:), and hyphens (-). Any other character will be replaced with a space.

Install BrowserStack plugin

On the Eclipse toolbar, click Help > Eclipse Marketplace. In the Eclipse Marketplace, search for BrowserStack > click Install > Finish.

Search for BrowserStack plugin

Configure your test suite with BrowserStack SDK

BrowserStack plugin automatically adds the browserstack-java-sdk dependency to your pom.xml file and generates a browserstack.yml configuration file.

Right-click on your project folder > BrowserStack > select Integrate with Automate SDK.

Screenshot showing the navigation from the project folder to BrowserStack to the Integrate with BrowserStack SDK option

Select your Project Folder, Framework, and other BrowserStack Parameters, and then click Integrate.

Screenshot showing the Integrate with BrowserStack SDK screen with parameters filled in

Update browserstack.yml file

Update the browserstack.yml file in the root folder of your test suite.

browserstack.yml
Copy icon Copy

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate as Test Reporting & Analytics will automatically identify different build runs.

Restrict the characters in your projectName and buildName to alphanumeric characters (A-Z, a-z, 0-9), underscores (_), colons (:), and hyphens (-). Any other character will be replaced with a space.

BrowserStack SDK is a powerful tool you can use to set the different browser/device combinations and parallelization. For more details, check out the Automate Integration guide or the App Automate integration guide.

Run your test suite

Run your tests as usual.

View results and insights on Test Reporting & Analytics dashboards

Post build run completion, you’ll be able to see the build run report along with all necessary debugging information.

Visit Test Reporting & Analytics

Setup for log4j in JUnit4

If you use log4j for your logs, you need to make a few changes to your test suite to support it.

  1. Add log4j properties file if not already done.

     logDir=logs
     # Initialize root logger with level ERROR for stdout and fout
     log4j.rootLogger=TRACE,stdout,fout
     # Set the log level for these components
     log4j.logger.com.endeca=INFO
     log4j.logger.com.endeca.itl.web.metrics=INFO
    
     # Add a ConsoleAppender to the logger
     log4j.appender.stdout=org.apache.log4j.ConsoleAppender
     log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
     # Use a simple message format
     log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n
    
     # Add a FileAppender to the logger
     log4j.appender.fout=org.apache.log4j.FileAppender
     log4j.appender.fout.File=logs/app.log
     log4j.appender.fout.layout=org.apache.log4j.PatternLayout
     log4j.appender.fout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n
    
  2. Define and use the logger.

     import org.apache.log4j.Logger;
     import org.junit.jupiter.api.Test;
     public class MyJUnit4Test {
         protected static Logger log = Logger.getLogger(MyJUnit4Test.class);
     // <your test code>
     }
    

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