Skip to content
Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Test Suites

XLT uses the concept of a test suite to make test projects more easily manageable.

Overview

An XLT test suite is a standalone Java project containing test scenarios, datasets, configuration, and dependencies. Because the test suite is decoupled from the load execution engine, you can version control it in Git, execute it locally inside your IDE for functional regression testing, and deploy it to distributed clusters for load testing.

Directory Structure

A standard XLT test suite uses the following directory layout:

test-suite/
├── config/             # Test properties, logging, and dataset files
│   └── data/           # Default directory for test data files
├── lib/                # Custom third-party JAR dependencies
├── src/                # Java or Kotlin source code
├── classes/            # Compiled bytecode (target/classes, bin/)
└── results/            # Local execution logs and Result Browsers
  • config/: Contains Test Settings files. The only mandatory file is log4j.properties, supplemented by project.properties, default.properties, and test.properties. Override the configuration directory using the system property com.xceptance.xlt.configDir or environment variable XLT_CONFIG_DIR.
  • config/data/: Default location for external test datasets consumed by DataProvider classes. Override via com.xceptance.xlt.data.directory.
  • lib/: Contains third-party JAR dependencies. When running distributed tests, the Master Controller archives and uploads only the files present in your test suite. For Maven builds, copy dependencies into target/dependency or lib/. See Building with Maven.
  • src/: Contains test case implementations and supporting domain classes.
  • Compiled Classes: XLT automatically scans common build output directories:
    • ./classes and ./bin
    • ./target/classes and ./target/test-classes (Maven)
    • ./build/classes/java/main and ./build/classes/java/test (Gradle Java)
    • ./build/classes/kotlin/main and ./build/classes/kotlin/test (Gradle Kotlin)
  • results/: Output directory for execution logs, measurement data, and Result Browsers. Override via com.xceptance.xlt.result-dir.

Applying Hotfixes and Code Patches

To override framework classes with project-specific patches, place updated classes or JARs into:

  • ./patches/classes/
  • ./patches/lib/

XLT prepends these locations to the agent classpath, loading patched classes ahead of standard framework binaries.

Code Organization & Architecture

Structure your source code under src/ following standard Java package conventions:

  • .../tests/: High-level test scenarios extending AbstractTestCase.
  • .../actions/: Page transition actions extending AbstractHtmlPageAction or AbstractAction.
  • .../flows/: Reusable multi-action workflow sequences.
  • .../validators/: Custom assertion and validation classes.
  • .../util/: Helper utilities and test data loaders.

Naming Conventions

Prefix test scenario classes with a capital T followed by descriptive camel-case terms indicating the journey:

  • TSearch
  • TCartCheckout
  • TGuestOrder
  • TAccountRegistration

This convention simplifies regex matching when selecting scenarios in test.properties (for example, com.xceptance.xlt.loadtests = T.*).

Core Test Concepts

An XLT test suite models user journeys using three primary building blocks:

1. Test Cases (Transactions)

An XLT test case represents one complete transaction. In code, each test case:

  • Extends AbstractTestCase.
  • Contains exactly one public test method annotated with @Test.
  • Can execute standalone in JUnit 4 runners (IDE, Maven Surefire) or distributed under the XLT Master Controller.

Inheriting from AbstractTestCase provides automated timer management, Result Browser capture on failure, and direct access to test properties.

2. Actions

An action represents an atomic interaction step that transitions the user from one state to another (for example, submitting a form or clicking a link).

Actions extending AbstractHtmlPageAction enforce a three-stage lifecycle:

  1. preValidate(): Verifies that the previous page contains required elements (such as input forms or buttons) before executing.
  2. execute(): Performs the interaction (e.g. typing text, submitting forms, clicking elements) and loads the target page.
  3. postValidate(): Asserts that the response succeeded and the newly loaded page contains expected content.

Calling action.run() executes this three-stage sequence automatically. To verify preconditions conditionally without throwing fatal errors, use action.preValidateSafe().

3. Flows

A flow bundles a sequence of related actions into a reusable procedural component. For example, a LoginFlow might execute OpenLoginPage, EnterCredentials, and SubmitLogin. Individual test scenarios call the flow method, eliminating duplicate code across tests.

4. Validators

To ensure test maintainability, extract recurring validation logic into dedicated validator classes implementing standard JUnit assertions.

XLT includes built-in validators in package com.xceptance.xlt.api.validators:

  • HttpResponseCodeValidator: Verifies HTTP status codes.
  • ContentLengthValidator: Ensures HTTP response bodies match declared content lengths.
  • HtmlEndTagValidator: Verifies valid HTML document closure (</html>).

Code Example: Implementing a Search Action

The following action searches for a keyword on an e-commerce storefront:

/**
 * Enter the given search phrase in the site's search bar and submit the form.
 */
public class Search extends AbstractHtmlPageAction
{
    /**
     * Search phrase.
     */
    private final String phrase;

    /**
     * Search form.
     */
    private HtmlForm searchForm;

    /**
     * Search option ({@link SearchOption#HITS} or {@link SearchOption#NO_HITS} ).
     */
    private final SearchOption searchOption;

    /**
     * Constructor
     *
     * @param previousAction
     *            The previously performed action
     * @param phrase
     *            The search phrase
     * @param option
     *            The search option that defines if we expect a hit or a no-hit
     */
    public Search(final AbstractHtmlPageAction previousAction,
                  final String phrase,
                  final SearchOption option)
    {
        super(previousAction, null);
        this.phrase = phrase;
        searchOption = option;
    }

    /**
     * Validation prior to execution.
     * @throws Exception
     *             if some of the required input elements couldn't be found.
     */
    @Override
    public void preValidate() throws Exception
    {
        // Get the current page.
        final HtmlPage page = getPreviousAction().getHtmlPage();
        Assert.assertNotNull("Failed to get page from previous action.", page);

        // Check that the search form is available
        Assert.assertTrue("Search form not found.", HtmlPageUtils.isElementPresent(page, "id('search')"));

        // Remember the search form
        searchForm = HtmlPageUtils.findSingleHtmlElementByID(page, "search");
    }

    /**
     * Executes the search. Primarily this includes the input of the search
     * phrase and a click on the proper search button.
     * @throws Exception
     *             if some of the inputs have become invalid or setting the
     *             value attribute of the search input field has failed.
     */
    @Override
    protected void execute() throws Exception
    {
        // Fill the search form with the given phrase
        HtmlPageUtils.setInputValue(searchForm, "searchText", phrase);

        // Submit the search
        loadPageByFormSubmit(searchForm);
    }

    /**
     * Validation after search has become complete.
     * @throws Exception
     *             if no search result block element could be found
     */
    @Override
    protected void postValidate() throws Exception
    {
        // Get the result of the action
        final HtmlPage page = getHtmlPage();

        // Basic checks - see action 'Homepage' for some more details how and when to use these validators
        HttpResponseCodeValidator.getInstance().validate(page);
        ContentLengthValidator.getInstance().validate(page);
        HtmlEndTagValidator.getInstance().validate(page);

        HeaderValidator.getInstance().validate(page);

        // Check that the desired option result was achieved.
        switch (searchOption)
        {
            case HITS:
                Assert.assertNotNull("Expected at least one hit for '" + phrase + "'.",
                                     HtmlPageUtils.findSingleHtmlElementByID(page, "productOverview"));
                break;

            case NO_HITS:
                Assert.assertFalse("Search phrase '" + phrase + "' should result in no hits.",
                                   HtmlPageUtils.isElementPresent(page, "productOverview"));
                break;

            default:
                Assert.fail("Unknown search option.");
                break;
        }
    }
}

Action Chaining & Context

The Search action constructor accepts two parameters:

  1. previousAction: The preceding action in the journey (Startpage), which provides access to the current HtmlPage and browser session context.
  2. phrase: The search query to submit.

Chaining actions via the previousAction parameter maintains browser state (cookies, active session, open page) across the user flow. Only the initial action in a journey creates a new browser instance without a preceding action.

XLT also provides StandardValidator to execute common checks in a single call:

  • HTTP response status code
  • HTML end tag presence
  • Content-Length header verification
  • XHTML conformance

Code Example: Implementing a Test Case

The following test case (TSearch) initializes test data and executes repeated searches:

public class TSearch extends AbstractTestCase
{
    // Container that holds all the search phrases
    private static DataProvider phrases = null;

    @Before
    public void initialize() throws Exception
    {
        // Data container already initialized?
        if(phrases != null) return;
        // No. Go for it.
        phrases = DataProvider.getInstance(getProperty("searchphrases.filename", "phrases.txt"));
    }

    @Test
    public void search() throws Throwable
    {
        // Start on Homepage.
        Startpage start = new Startpage();
        start.run();

        for (int i = 0; i < XltRandom.nextInt(10); i++)
        {
            // Take a random search phrase.
            String searchPhrase = phrases.getRandomRow(false);

            // Search.
            Search search = new Search(start,searchPhrase);
            search.run();
        }
    }
}

Test Data Management with DataProvider

The DataProvider class provides cached, in-memory access to dataset files stored under <testsuite>/config/data/:

  • Load datasets by specifying file paths relative to config/data/ (for example, DataProvider.getInstance("phrases.txt")).
  • Retrieve values sequentially or randomly using methods like getRandomRow(false).
  • For common synthetic data (names, addresses, credit cards), use GeneralDataProvider.

Randomization with XltRandom

Use XltRandom (package com.xceptance.xlt.api.util) to generate deterministic or pseudo-random values for test parameters, think times, and iteration counts. Unlike standard java.util.Random, XltRandom is optimized for concurrent virtual threads and provides range helpers for strings, integers, and choices.

Last updated on