Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Seed the backend before Selenium opens the React app: use Spring’s @Sql for repeatable database fixtures in integration tests, or create records through a supported test API or database setup step before a browser test. Then let Selenium focus on the user actions and visible results. This keeps setup faster and less brittle than creating every prerequisite through the UI.

Choose the setup method for the test layer

“Dummy data” can mean a few different things: sample records for a Spring integration test, prerequisite state for an end-to-end browser workflow, or data that must exercise the behavior of a particular database engine. These are related but not interchangeable. Decide which layer owns the behavior under test, and prepare state at the lowest layer that still gives the test meaningful coverage.

Test goal Good starting point What it verifies
Spring service or API behavior against seeded records Spring integration test with @Sql Application behavior using fixture rows in the configured test database
React workflow with backend data already available Test API or database setup before Selenium starts The user journey and visible UI response, without spending browser time creating all prerequisites
Behavior specific to the production database engine Disposable database container plus Spring fixture setup Integration behavior against the chosen database engine and its constraints

Keep application startup initialization separate from test fixtures. Boot’s datasource initialization is part of application startup, and ordering depends on how the schema is created. Spring TestContext’s @Sql is explicitly tied to a test class or method and can run scripts before or after a test. For test-specific data, use a test lifecycle mechanism rather than assuming startup scripts are the right place. See the Spring Boot datasource initialization guidance and the Spring Framework 5.2 testing reference; verify behavior against the versions your project uses.

Seed Spring integration tests with SQL fixtures

Place the fixture in test resources and associate it with the test class or method that needs it. A minimal example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@SpringBootTest
@Sql(scripts = "/test-data.sql")
class CustomerApiTest {
    // Test the behavior that depends on the seeded customer.
}

For example, src/test/resources/test-data.sql might insert a customer row using the schema and required fields of your application. The script path begins at the test classpath root. Adapt table names, constraints, values, and paths to the actual schema; the annotation does not define a universal fixture format.

Control when scripts run

@Sql accepts script resources and supports an execution phase. Use the default before-test execution for setup; an after-test script can perform SQL cleanup when that suits the test’s transaction model. Spring’s testing reference also documents @SqlConfig for script parsing and transaction settings such as custom separators and comment prefixes. Configure transaction behavior deliberately if the test needs seeded rows to be committed and visible outside the test transaction.

Class-level and method-level @Sql declarations have merge behavior that can be configured. Do not assume that declaring scripts at both levels automatically combines them in the way you intend. Check the Spring Framework documentation matching your dependency version, then make the chosen behavior explicit.

Keep schema creation and fixture insertion compatible

Run the schema-creation mechanism your application uses before a fixture inserts into its tables. A mismatch can appear as a missing table, a missing column, or an insert rejected by a constraint. Spring Boot’s initialization ordering has changed across versions and depends on schema management choices; the Spring Boot 2.5-era datasource initialization guidance is not a substitute for checking the reference documentation for the Boot version in your build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prepare React browser-test data before Selenium

For an end-to-end test, create the account, order, or other required record through a supported test API or a database fixture step before opening the React page. Selenium’s test-automation guidance recommends separating data setup from browser actions where another route is available. Browser tests are relatively expensive, so use them to test what a user does and sees, not to perform all backend setup through clicks.

  1. Create a unique test record through an authorized test API or fixture setup.
  2. Launch a fresh WebDriver session appropriate to the test runner.
  3. Open the React route for that record, authenticate if required, and perform the specific user action being tested.
  4. Assert the result visible in the interface, such as the record’s displayed status or content.
  5. Remove or expire the test record and close the browser session.

The exact way to connect a React screen to a seeded backend record depends on the app’s API, authentication, and routing. For example, one application may route by a record ID, while another may show records from the current user’s account. Choose setup values and navigation based on the real contract; there is no single React fixture annotation that works for every architecture.

Keep the browser test about the user workflow

Once its prerequisites exist, the browser test should exercise the behavior that merits a browser: navigation, form interaction, client-side validation, rendering, or a full workflow across the UI. If the expected result can be tested at a service or component layer, consider doing so there instead. Selenium’s test automation guidance discusses keeping browser tests focused; its state-sharing guidance recommends avoiding shared mutable test state.

Isolate records, sessions, and cleanup

Repeated and parallel runs become unreliable when tests depend on the same mutable row or leave stale data behind. Give each test a distinct record identifier or other unique business key. Do not have one test assume another test has already created or modified its record.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use unique fixture values when tests may run concurrently.
  • Make cleanup safe to repeat, and scope it so it cannot remove another test’s data.
  • Use a separate WebDriver instance per test when that fits the runner and lifecycle; avoid carrying browser state across unrelated tests.
  • Use disposable test databases or schemas when isolation requirements make shared state difficult to control.

Spring’s test transaction rollback can help for some integration tests, but it does not automatically solve every browser-test lifecycle: a browser may use a separate request and transaction, while setup data that has not been committed may not be visible to it. Confirm whether the setup and application requests share a transaction boundary, and commit setup state when the app must read it independently.

Use Testcontainers when database fidelity matters

If the behavior depends on a particular database engine—such as its constraints, SQL dialect, or transaction behavior—a lightweight substitute may not reproduce the issue. Testcontainers can provide a temporary database for tests, after which Spring can seed it with SQL fixtures. Its guide demonstrates a PostgreSQL container in a Spring Boot integration-test context, and its Java documentation covers the container testing library: Testcontainers guide and Testcontainers for Java documentation.

This approach adds a container runtime requirement and startup cost. The cited guide’s Spring Boot example uses PostgreSQL and Boot 3.1-era service-connection support; treat it as a version-specific example, not a drop-in dependency recipe for every project. Use a simpler test database when production-engine fidelity is not material to the behavior being tested.

Common failures and practical fixes

Symptom Likely cause What to check
Fixture script cannot be found Classpath path is wrong or resource is not under test resources Place the file in the test classpath and use the correct root-relative path in @Sql.
Insert fails because a table or column is missing Schema setup has not run, or the fixture targets a different schema version Check schema creation and initialization ordering for the project’s Spring Boot version.
React page does not show the seeded row Setup is uncommitted, the browser is using another database/profile, or the route/user does not expose that row Verify the test profile, database connection, transaction visibility, authentication, and API response used by the page.
Tests pass alone but fail in a suite or in parallel Shared identifiers, stale state, or shared browser sessions Use unique data, isolate sessions, and make teardown scoped and repeatable.
Testcontainers cannot start its database Container runtime is unavailable or container configuration does not match the test setup Check the local or CI container runtime and confirm the database image, connection details, and library versions.
Cleanup removes data needed by another test Broad delete statement or shared fixture key Delete only records created by the current test, preferably using its unique key.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and maintenance trade-offs

The browser is usually the most expensive part of this setup. Creating records through API or SQL setup shortens the UI portion and reduces dependence on selectors and intermediate screens. SQL fixtures are deterministic and close to the test, but they can become coupled to schema details. Test APIs can express business-valid setup, but rely on the API and its authorization contract. Testcontainers improve engine fidelity, while requiring container infrastructure and time to start it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A useful maintenance rule is to keep a fixture as small as the behavior requires. A test for displaying one customer should not depend on an entire unrelated catalog of rows. When fixture SQL becomes hard to maintain because domain rules are complex, a supported test setup API or factory may better preserve application invariants. Whichever setup method you choose, keep its records identifiable and its cleanup bounded.

Or skip the browser setup

If the goal is a screenshot artifact rather than Selenium interaction coverage, ScreenshotNeo can capture a page without configuring a browser test. Its API accepts one GET request with the target URL and returns an image or PDF. See the ScreenshotNeo website and API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Replace the example URL with a page your test environment makes reachable and supply your API key. This captures a page; it does not replace Selenium assertions or create backend test records. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses identify the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Version and scope notes

The setup pattern applies broadly, but exact annotation behavior and dependencies depend on the project’s versions. The cited @Sql reference is Spring Framework 5.2 documentation; confirm its attributes and merge semantics against the framework actually in use. Spring Boot datasource initialization guidance cited above is a 2021 project wiki page, while current Boot reference documentation is the authority for a specific Boot release. The Testcontainers PostgreSQL example is not evidence that every app uses PostgreSQL or Boot 3.1. Choose the guidance that matches the database, Spring Boot release, test runner, and Selenium binding in your project.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.