Variable Groups
Variable Groups are the backbone of dynamic testing in ReAPI. They are named sets of key-value pairs that provide the specific configuration values for your different environments, user roles, and test scenarios.
They are designed to work in concert with Servers and Authentication profiles by providing the dynamic values those components need at runtime.
Role of a Variable Group
A variable group’s primary job is to store any value that might change when you switch testing contexts. This includes:
- Server URLs: Hostnames for your services in different environments (dev, staging, prod).
- Authentication Credentials: API keys, tokens, usernames, and passwords.
- Test Data: User IDs, account numbers, or any other data specific to an environment.
- Configuration Flags: Feature flags or other environment-specific settings.
Using Variables
Anywhere in ReAPI that supports dynamic input, you can reference a value from the active variable group using the {{variable_name}} syntax.
Example:
If your variable group contains { "userId": "user-123" }, you can use {{userId}} in a URL, header, or request body, and it will be replaced with user-123 at runtime.
Inheritance and Nested Groups
To reduce duplication and make your configuration easier to manage, Variable Groups support parent-child inheritance.
A child group automatically inherits all the key-value pairs from its parent. You can then add new variables or override inherited ones in the child group. This is the recommended way to manage complex configurations.
Common Pattern: Environment and Role Separation
A powerful pattern is to separate your environment configuration from your user role configuration.
-
Create a “Base” Parent Group for an Environment: This group holds all the common values, like server URLs.
Parent Group:
Staging - Base{ "auth_url": "https://auth.staging.myapi.com", "user_url": "https://users.staging.myapi.com" } -
Create Child Groups for User Roles: These groups inherit from the base and provide only the role-specific credentials.
Child Group:
Staging - Admin User(Inherits fromStaging - Base){ "api_token": "staging-token-for-admin-user" }
When you select the Staging - Admin User group, your tests will have access to all three variables: auth_url and user_url from the parent, and api_token from the child. If an inherited variable is redefined in a child group, the child’s value will always be used.