Overview
The Makers BTG Tests project uses Gradle as its build tool. Thebuild.gradle file defines project dependencies, Java version, test configuration, and Serenity BDD integration.
Project Configuration
build.gradle
Plugins
Provides Java compilation, testing, and packaging capabilities.
Version:
4.0.46Integrates Serenity BDD into the Gradle build lifecycle:- Aggregates test results
- Generates HTML reports
- Manages Serenity dependencies
- Provides
aggregatetask for report generation
Project Identity
Value:
org.btg.practualMaven group ID for the project.Value:
1.0.0-SNAPSHOTCurrent project version. SNAPSHOT indicates this is a development version.Java Toolchain
build.gradle
Value: Java 21Configures the Java version for compilation and execution.Benefits of toolchains:
- Gradle automatically downloads Java 21 if not installed
- Ensures consistent Java version across all developers
- Prevents “works on my machine” issues
- CI/CD uses the exact same Java version
Java 21 is a Long-Term Support (LTS) release with modern language features including:
- Virtual Threads (Project Loom)
- Pattern Matching for switch
- Record Patterns
- Sequenced Collections
Dependency Versions
build.gradle
ext block):
Serenity BDD framework version used across all Serenity dependencies.
JUnit 5 (Jupiter) version for test execution.
Using
ext properties ensures all related dependencies use the same version, preventing compatibility issues.Dependencies
build.gradle
Dependency Categories
1. Serenity BDD Core & Cucumber
1. Serenity BDD Core & Cucumber
Version: 4.0.46Core Serenity BDD framework providing:
- Test orchestration
- Report generation
- Screenshot capture
- WebDriver management
Version: 4.0.46Integration between Serenity BDD and Cucumber for BDD-style testing:
- Gherkin feature file support
- Step definition integration
- BDD report generation
2. Screenplay Pattern
2. Screenplay Pattern
Version: 4.0.46Core Screenplay pattern implementation:
- Actor-based test design
- Task and Question abstractions
- Interaction modeling
- High-level test readability
Version: 4.0.46Web UI interactions for Screenplay:
- Browser actions (Click, Enter, Open)
- Element queries (Text, Value, Visibility)
- Navigation and frame switching
- WebDriver integration
3. JUnit 5 Test Engine
3. JUnit 5 Test Engine
Version: 5.10.1JUnit 5 API for writing tests:
@Testannotations- Lifecycle hooks (
@BeforeEach,@AfterEach) - Assertions
Version: 5.10.1JUnit 5 test execution engine. Runtime-only dependency as tests don’t directly import engine classes.
Version: 1.10.1Enables test suite configuration with
@Suite and @IncludeEngines annotations for running Cucumber tests.4. AssertJ
4. AssertJ
Version: 3.24.2Fluent assertion library providing readable and powerful assertions:More expressive than standard JUnit assertions.
5. Logging
5. Logging
Version: 1.4.14Logging framework (SLF4J implementation) for test execution logging:
- Configurable log levels
- File and console output
- Pattern-based formatting
src/test/resources/logback-test.xml6. Cucumber JUnit Platform Engine
6. Cucumber JUnit Platform Engine
Version: 7.14.0Enables Cucumber to run as a JUnit Platform test engine. Required for
@IncludeEngines("cucumber") annotation in test runners.Bridges Cucumber feature execution with JUnit Platform.7. JUnit 4 (Compatibility)
7. JUnit 4 (Compatibility)
Version: 4.13.2JUnit 4 dependency required by Serenity’s reporting mechanism. Even though tests use JUnit 5, Serenity’s internal reporter needs JUnit 4.
This is a compatibility requirement and doesn’t affect your test code.
Build Configuration
Encoding
build.gradle
Ensures all Java source files are compiled using UTF-8 encoding.Why important: Prevents encoding issues with special characters in code, comments, or test data across different operating systems.
Test Task Configuration
build.gradle
Test Platform
Configures Gradle to use JUnit Platform (JUnit 5) for test execution.Required for running JUnit 5 and Cucumber tests via JUnit Platform.
Test Logging
Values:
["passed", "skipped", "failed"]Logs test events to the console:- ✅ passed: Successful tests
- ⏭️ skipped: Skipped tests
- ❌ failed: Failed tests with stack traces
Displays
System.out and System.err output in the console during test execution.Useful for debugging but can create verbose output.System Properties
Passes all JVM system properties from the command line to test execution.Enables runtime configuration:
Value:
org.btg.practualRoot package for scanning test classes and step definitions.Value:
Makers BTG TestsProject name displayed in Serenity HTML reports.Gradle Start Parameters
build.gradle
Ensures Gradle continues executing all tests even if some fail, instead of stopping at the first failure.Benefits:
- Complete test coverage in one run
- Full test report generation
- Better CI/CD feedback
Essential for CI/CD pipelines to get complete test results rather than stopping at the first failure.
Serenity Plugin Configuration
build.gradle
Value:
org.btg.practualRoot package for test scanning (matches systemProperty).Value:
src/test/resources/featuresDirectory containing Cucumber feature files for requirements traceability in reports.Value:
["html"]Report formats to generate. HTML provides rich visual reports with screenshots and step details.Report Generation
build.gradle
Automatically runs the
aggregate task after tests complete.The aggregate task:- Collects test results from all test executions
- Generates consolidated Serenity HTML reports
- Creates requirements traceability documentation
target/site/serenity/View reports by opening
target/site/serenity/index.html in a browser.Common Gradle Commands
Dependency Management Best Practices
Keep Versions Aligned
All Serenity dependencies should use the same version
Use Version Variables
Centralize versions in
ext block for easy updatesRegular Updates
Check for newer stable versions periodically
Test After Upgrades
Run full test suite after dependency updates
Troubleshooting
Build Failures
Java Version Mismatch
Java Version Mismatch
Error:
Unsupported class file major versionSolution: Ensure Java 21 is installed or let Gradle download it:Dependency Resolution Failures
Dependency Resolution Failures
Error:
Could not resolve net.serenity-bdd:serenity-core:4.0.46Solution: Check internet connection and Maven Central access:Test Task Not Found
Test Task Not Found
Error:
Task 'test' not foundSolution: Ensure you’re in the project root directory with build.gradleReports Not Generated
Reports Not Generated
Check that
test.finalizedBy(aggregate) is present in build.gradleManually generate reports:Dependency Conflicts
View dependency tree to identify conflicts:Upgrading Dependencies
Check for Updates
Update Serenity Version
-
Update version in
build.gradle: -
Update plugin version:
-
Refresh dependencies:
CI/CD Integration
GitHub Actions Example
.github/workflows/test.yml
Gradle toolchain will ensure Java 21 is used even if the system has a different version installed.