Variable

A variable is a named placeholder that stores values which can change during test execution, such as URLs, credentials, or configuration settings.

Table of Contents

Table of Contents

What Does Variable Mean?

A variable is a symbolic name or placeholder that stores values which may change during test execution. Variables define inputs, configurations, or parameters without hardcoding data.

That makes tests more dynamic and reusable across environments and scenarios.

Hardcoded Values vs. Variables

Aspect Hardcoded Values Variables
Environment changes Edit the test for each environment Pass a new value at runtime
Reuse One copy per environment or dataset One definition used everywhere
Security Credentials may end up in code Sensitive values come from secret stores
Maintenance Many copies drift apart Update values in one place
Example A staging URL written into the script BASE_URL set per environment

Common Types of Variables in Testing

  • Environment variables: values injected into the runtime, such as base URLs or region names
  • Configuration parameters: inputs like timeouts, user counts, or feature flags
  • Secrets: sensitive values such as API keys and passwords, stored securely
  • Test data variables: datasets or IDs that change between scenarios

Why Variables Matter

Variables make testing workflows adaptable and maintainable. Teams parameterize values like URLs, credentials, or resource names instead of duplicating tests. This helps teams:

  • Reuse test definitions across multiple environments
  • Reduce duplication and maintenance overhead
  • Control test behavior dynamically at runtime
  • Scale consistently across automated testing workflows

Variables are fundamental to configuration-as-code and infrastructure-agnostic testing.

How Variables Work with Testkube

  • Workflow configuration: Variables can be defined directly in a test workflow to customize execution.
  • Environment variables: Testkube injects environment variables into test pods for dynamic runtime values.
  • Secrets and ConfigMaps: Sensitive or structured values are stored and managed as Kubernetes resources.
  • Workflow parameterization: The same workflow adapts across clusters, namespaces, or pipelines.
  • CLI and API support: Values can be passed through the Testkube CLI or API when triggering runs.

Real-World Example

A B2B SaaS team runs the same k6 load test against staging and a production mirror. Each environment has a different URL, user count, and API key.

  1. Define variables: the workflow declares BASE_URL and VIRTUAL_USERS.
  2. Store secrets: the API key lives in a Kubernetes Secret.
  3. Pass values: each CI pipeline supplies its own values when triggering the run.

One workflow now covers both environments, and the API key never appears in code.

Best Practices for Using Variables

  • Never hardcode secrets: Store credentials in Secrets or a secrets manager.
  • Use clear names: Names like BASE_URL explain themselves to other teams.
  • Set sensible defaults: Defaults make tests easy to run locally.
  • Document required variables: List inputs so others can reuse the test quickly.
  • Validate inputs early: Fail fast when a required value is missing.

Frequently Asked Questions (FAQs)

What is a variable in testing?

A variable is a named placeholder that stores values which can change during test execution. Examples include URLs, credentials, and configuration settings.

Why use variables instead of hardcoded values?

Variables let one test run across many environments and datasets. They reduce duplication and keep sensitive values out of code.

What is the difference between a variable and a secret?

A secret is a variable that holds sensitive data, such as an API key. It is stored and injected securely instead of being written in plain text.

How does Testkube handle variables?

Testkube supports variables in workflow definitions, environment variables in test pods, and Kubernetes Secrets and ConfigMaps. Values can also be passed through the CLI or API.

Can I change variables when triggering a test run?

Yes. You can pass values through the Testkube CLI or API at trigger time, so each run uses the right configuration.

Related Terms and Concepts

No items found.