Skip to main content
Version: Latest

Testing Overview

Brobot provides comprehensive testing capabilities designed for GUI automation reliability and maintainability. The framework supports multiple testing approaches, each serving specific purposes in the automation testing lifecycle.

Advanced Testing Features

For advanced mock testing capabilities including scenario-based configurations and failure patterns, see the Enhanced Mock Testing System in the Core Library documentation.

Testing Typesโ€‹

Integration Testingโ€‹

Purpose: Validate complete automation workflows and system reliability

  • Full workflow simulation using mock execution
  • Stochastic modeling of real-world variability and failure modes
  • State transition validation across complex application flows
  • Performance and reliability assessment for production readiness
  • Optimized execution with parallel testing and shared contexts

Performance Features:

  • Parallel test execution using available CPU cores
  • Shared Spring contexts via OptimizedIntegrationTestBase
  • Ultra-fast mock timings (0.005-0.04s per operation in test profile)
  • JVM forking (every 20 tests) to prevent memory issues
  • Test result caching for faster re-runs

Best for: End-to-end workflow validation, reliability testing, CI/CD pipeline integration

For comprehensive integration testing patterns with Spring Boot, see the Integration Testing Guide.

Unit Testingโ€‹

Purpose: Test individual components with deterministic, reproducible results

  • Isolated component testing using static screenshots
  • Deterministic results with known screen states
  • Fast execution with mocked actions
  • Regression detection for code changes

Best for: Component validation, regression testing, development workflows

For detailed unit testing patterns with BrobotTestBase, see the Unit Testing Guide.

Action Recordingโ€‹

Purpose: Visual validation and debugging of automation behavior

  • Visual verification of action execution
  • Interactive debugging and development
  • Screenshot-based validation with real-time feedback
  • Manual testing support for complex scenarios

๐Ÿ’ก Visual Debugging: Brobot's highlighting feature provides real-time visual feedback during automation. See the Highlighting Feature Guide for details on visual debugging and validation techniques.

Best for: Development debugging, manual verification, complex scenario validation

Configuration Architectureโ€‹

Modern Configuration Systemโ€‹

Brobot uses Spring Boot's configuration properties system with clean architectural patterns:

Test Logging Configuration

Brobot includes a clean test logging architecture that follows Single Responsibility Principle and eliminates circular dependencies.

Configuration Propertiesโ€‹

# Core testing settings
brobot.mock=true
brobot.core.image-path=images/

# Screenshot management
brobot.screenshot.path=screenshots/
brobot.screenshot.save-snapshots=false
brobot.screenshot.save-history=true

# Mock execution timings
brobot.mock.time-find-first=0.1
brobot.mock.time-click=0.05
brobot.mock.time-drag=0.3

# Testing behavior
brobot.testing.iteration=1
brobot.testing.send-logs=true

Or using YAML format:

brobot:
mock: true
core:
image-path: images/
screenshot:
path: screenshots/
save-snapshots: false
save-history: true
mock:
time-find-first: 0.1
time-click: 0.05
time-drag: 0.3
testing:
iteration: 1
send-logs: true

Migration from Legacy APIโ€‹

For applications migrating from Brobot 1.0.x, the following APIs have been modernized:

Legacy (1.0.x)Modern (1.1.0+)Notes
Direct settings manipulationbrobot.mock=trueUse properties instead of code configuration
Manual screenshot configurationbrobot.screenshot.pathConfigure via properties
ActionOptions classesActionConfig classes (e.g., PatternFindOptions, ClickOptions)New fluent builder API

See Upgrading to Latest for complete migration guide.

Testing Workflowโ€‹

1. Configuration Setupโ€‹

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import io.github.jspinak.brobot.actions.actionExecution.Action;
import io.github.jspinak.brobot.manageStates.StateService;

@SpringBootTest
@TestPropertySource(properties = {
"brobot.mock=true",
"brobot.screenshot.path=src/test/resources/screenshots/"
})
class AutomationTest {

@Autowired
private Action action;

@Autowired
private StateService stateService;

// No manual configuration needed - handled by properties
}

2. Test Executionโ€‹

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.jupiter.api.Assertions.*;
import io.github.jspinak.brobot.actions.actionExecution.Action;
import io.github.jspinak.brobot.reports.ActionResult;
import io.github.jspinak.brobot.actions.actionConfigs.PatternFindOptions;
import io.github.jspinak.brobot.datatypes.state.stateObject.stateImage.StateImage;

@Test
void testAutomationFlow() {
// Create action configuration
PatternFindOptions findOptions = new PatternFindOptions.Builder()
.setStrategy(PatternFindOptions.Strategy.BEST)
.setSimilarity(0.85)
.build();

// Create state object
StateImage loginButton = new StateImage.Builder()
.addPattern("login_button") // No .png extension needed
.build();

// Execute automation with mock/real behavior based on configuration
ActionResult result = action.perform(findOptions, loginButton);

// Modern assertion patterns
assertTrue(result.isSuccess());
assertFalse(result.isEmpty());
assertEquals(1, result.size());
}

3. Result Validationโ€‹

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Optional;
import java.util.List;
import io.github.jspinak.brobot.actions.actionExecution.Action;
import io.github.jspinak.brobot.reports.ActionResult;
import io.github.jspinak.brobot.actions.actionConfigs.PatternFindOptions;
import io.github.jspinak.brobot.datatypes.state.stateObject.stateImage.StateImage;
import io.github.jspinak.brobot.datatypes.primitives.match.Match;
import io.github.jspinak.brobot.datatypes.primitives.region.Region;

@Test
void validateResults() {
// Perform find action
PatternFindOptions findOptions = new PatternFindOptions.Builder()
.setStrategy(PatternFindOptions.Strategy.ALL)
.build();

// Create StateImage for testing
StateImage buttonsImage = new StateImage.Builder()
.addPattern("buttons")
.setName("buttons")
.build();

ActionResult result = action.perform(findOptions, buttonsImage);

// Test ActionResult properties
Optional<Match> bestMatch = result.getBestMatch();
assertTrue(bestMatch.isPresent());
assertTrue(bestMatch.get().getScore() > 0.8);

// Test regions and coordinates
List<Region> regions = result.getMatchRegions();
assertThat(regions).hasSize(2);
}

Testing Best Practicesโ€‹

Test Organizationโ€‹

  • Separate test configurations for different testing types
  • Use descriptive test names that indicate the scenario being tested
  • Organize screenshots in logical directory structures
  • Version control test assets including screenshots and configurations

Configuration Managementโ€‹

  • Use properties files for environment-specific settings
  • Leverage Spring profiles for different testing scenarios
  • Document configuration requirements for each test type
  • Validate configuration in test setup methods

Assertion Strategiesโ€‹

  • Test positive and negative cases for comprehensive coverage
  • Use appropriate assertion granularity (component vs. workflow level)
  • Implement custom matchers for domain-specific validations
  • Include timing and performance assertions where relevant

Framework Integrationโ€‹

Spring Boot Integrationโ€‹

For conflict-free test configuration, use Profile-Based Testing:

@SpringBootTest(classes = IntegrationTestMinimalConfig.class)
@ActiveProfiles("integration-minimal")
@TestPropertySource(locations = "classpath:application-integration.properties")
class IntegrationTest extends IntegrationTestBase {
// Isolated test configuration without bean conflicts
}

Standard Configurationโ€‹

@SpringBootTest
@ActiveProfiles("test")
class IntegrationTest {
// Full Spring context with Brobot configuration
}

JUnit 5 Supportโ€‹

@ExtendWith(MockitoExtension.class)
class UnitTest {
@Mock
private SomeService mockService;

// Standard JUnit 5 patterns with Brobot
}

CI/CD Pipeline Supportโ€‹

  • Headless execution for automated environments
  • Configurable timeouts for different environments
  • Test result reporting with detailed logs
  • Screenshot archival for test failure analysis

Getting Startedโ€‹

  1. Choose your testing approach based on requirements
  2. Configure properties for your testing environment
  3. Set up test screenshots or mock data as needed
  4. Implement test cases using modern APIs
  5. Validate and iterate based on test results

Quick Performance Setupโ€‹

To enable optimized test execution for integration tests:

  1. Add to library-test/gradle.properties:
org.gradle.parallel=true
org.gradle.caching=true
systemProp.junit.jupiter.execution.parallel.enabled=true
  1. Update library-test/build.gradle:
test {
timeout = Duration.ofMinutes(10)
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2)
forkEvery = 20
}
  1. Use optimized base class:
public class MyTest extends OptimizedIntegrationTestBase {
// Automatic performance optimizations
}

For detailed examples and advanced patterns, see the specific testing type documentation.

Essential Testing Guidesโ€‹

Mock Mode & Testingโ€‹

Testing Utilitiesโ€‹

Configuration & Setupโ€‹

ActionConfig Systemโ€‹

Advanced Testing Featuresโ€‹