Seeding and Resetting

Learn how to use seed data to create a consistent environment for testing.

Overview

To get the most out of testing in Rainforest, you might need to configure your testing environment with seed data. This article helps you prepare your QA environment so that it’s ready for testing in Rainforest.

Definitions

Seeding

Preparing data in your application for testing is called “seeding.” For example, if you have a test that creates a report, you need data to display and verify. Or, if you want testers to log in, you need test accounts with login credentials. Seed your environment to make sure it is ready to be tested. Create seeded accounts to make sure account details and settings are prepared before the testers start testing.

Isolation

Sometimes, tests must execute independently without adversely affecting the outcome of other tests. For some applications, using multiple user accounts is sufficient. For others, if the scope of a test’s actions is larger than a single user account, then the extent of their isolation must be greater as well. For example, your app might include organizations or teams, and each tester needs their own.

Resetting

Each time a test executes, our testers work with test accounts, and the data is modified according to the test steps. To rerun the test, the data must return to its starting state so the test doesn’t fail. Your application should do this by restoring the database image or running a migration.

Sample Techniques for Preparing Your QA Environment

Factories

In object-oriented programming (OOP), a factory is code that creates an object. Use factories in your seeding scripts to provide realistic data for testing. Factory Bot and Factory Boy are two popular options for Ruby and Python.

>>> user = UserFactory.build(first_name='Joe')
>>> user.first_name
"Joe"

Faker

Many programming languages offer faker packages. Their purpose is to create believable data for testing. For example, you might call faker.first_name to return a person’s first name from a list.

Here are a few of the many faker packages available:

fake = Faker()

fake.name()
# 'Mars Williams'

Production Data

Copying data from Production is often the fastest way to create data for testers. However, using live data can introduce privacy concerns around personally identifiable information (PII), such as address, phone number, and Social Security number.

If you decide to use production data for testing, make sure to anonymize it first. To learn more, check out The Fundamentals of Data Anonymization and Protection from DATAVERSITY.

Webhooks

Rainforest uses webhooks to notify you when a test has started or stopped so you can perform any required setup or teardown steps. For more information, see Using Webhooks.


Method POST
URL  https://my-staging-app.com/webhooks/rainforestqa
Body  {
     “callback_type”: “before_run”,
     “options”: {
       “run_id”: “12345”
     },
     “digest”: “ADIGESTSTRING”
   }

Seeded State Management

A seeded state means your test environment is already populated with the required test data, ensuring your Visual Editor test executes as expected. Seeding data in your preproduction environment allows tests to complete faster while using fewer steps.

Seeded states are beneficial as you build out your test suite. They help to maintain a test environment that is consistent and predictable. With Rainforest, there are several ways to keep your environment clean while testing with seed data.

Note: The methods described below are not mutually exclusive.

Using Your CI Process to Reset a Staging Environment Database

For teams working on a typical two-week agile sprint cycle, using your CI server to reset your database (DB) is an easy way to ensure a clean test environment for each run. For more information, see Using the CLI for Continuous Integration.

Using a Rainforest Webhook to Trigger a Database Reset

If you don’t use a CI tool, you can maintain a clean test environment by resetting your database using a webhook. We recommend using a simple webhook whenever possible. If your DB reset takes longer than 25 seconds, use an advanced webhook. Fore more information, see our Using Webhooks article.


If you have any questions, reach out to us at [email protected].