Table of content
- Introduction
- What is a Test Suite?
- Types of Test Suites
- What is a Test Case?
- Structure of a Test Case
- What is a Test Setup?
- Types of Setups
- Test Setup vs Test Teardown
- Conclusion
Introduction
Robot Framework is a popular, open-source test automation framework that uses plain English syntax to make test automation accessible to both technical and non-technical users. A key part of mastering Robot Framework is understanding its building blocks: Test Suites, Test Cases, and Test Setup. This blog post dives into each concept with practical examples.
What is a Test Suite?
In Robot Framework, a set of test cases is called a test suite. Test suites facilitate the logical grouping of tests and simplify the management of automation for larger projects. It helps you organize your test cases by features, functionality, or modules.
Let’s look at project structure as an example:
Types of a Test Suite:
A test suite in Robot Framework can exist in three main forms:
1. Single File Suite
- Each .robot file under the tests/ directory is an individual test suite. It means .robot file with test cases is considered a test suite. For example:
Example: (Consider the above snapshot)
addaccounts.robot is a test suite for "Add Accounts" functionality.
login.robot contains test cases related to login — it's another suite.
You can run them individually like this:
| robot tests/login.robot |
2. Directory-Based Suite
- A folder containing multiple .robotfiles is also treated as a suite. Robot Framework will automatically detect all test files inside it and run them as a group.
- The tests/ folder itself is a test suite that contains all the .robot files inside it. Robot Framework will recursively pick up and execute all test cases in all files when you run the folder.
You can run the whole suite like this:
| robot tests/ |
3. Nested Suites (Hierarchical Structure)
- You can create subfolders within a suite folder, forming a hierarchy. Each folder becomes a suite, and Robot Framework treats the whole directory tree as a suite collection.
- You could further group tests in subfolders by modules if needed (e.g., tests/accounts/, tests/leads/). Each subfolder would become a suite, and files inside would be sub-suites.
Why Use Test Suites?
Using test suites gives you several benefits:
- Structured Tests: Facilitates differentiating tests based on features, modules, or user roles.
- Scalability: Less complicated to handle big projects by splitting tests logically.
- Selective Execution: Execute only certain test suites when necessary (i.e., execute payment_tests.robot only).
- Centralized Setup/Teardown: Declare common setup/teardown operations at the suite level rather than duplicating them for every test case.
| Element | Role in Robot Framework |
| tests/login.robot | Individual test suite with login cases |
| tests/ folder | Folder-level test suite containing all tests |
| pages/ folder | Support files with keywords (not suites) |
| robot tests/login.robot | Command to run a single suite |
| robot tests/ | Command to run the full test suite |
What is a Test Case?
- A Test Case in Robot Framework is the most basic unit of execution, intended to check some specific functionality or behavior in your application. Test cases are authored using keywords—these may be built-in, library-based, or customized.
- Every test case is contained within a .robot file, and every .robot file may contain one or more test cases.
Structure of a Test Case:
A test case contains:
- A name
- A list of keywords to execute
Tests/
├── login.robot
├── addaccounts.robot
├── searchlead.robot
└── ...
Each of these files contains test cases. Let's break it down with examples:
- Each test case starts with a name (like Valid Login)
- Follows a sequence of steps using keywords
- Can include metadata like Documentation, Tags, etc.
You can run test case like this:
| robot --test "Valid Login" tests/login.robot |
Using clear, independent test cases helps:
- Test individual features (e.g., login, search, create)
- Identify bugs in specific scenarios
- Maintain and update tests easily
- Reuse common steps via user-defined keywords
| Terms | Meaning |
| Test Case | A scenario that checks a specific feature or flow |
| Location | Inside .robot files like login.robot or addaccounts.robot |
| Content | Series of steps written using keywords |
| Naming | Each test has a descriptive name |
| Execution | You can run all or specific test cases selectively |
What is a Test Setup?
- In Robot Framework, a Test Setup is a block of code (a keyword or set of steps) that executes before every test case or before the test suite begins. It is used to execute common preconditions such as opening a browser, logging in, loading test data, or going to a particular page.
- Having Test Setup makes your tests neater, more readable, and maintainable.
This is useful for:
- Preparing test environments
- Opening browsers
- Logging in
- Loading data or configurations
Types of Setups:
Robot Framework have below two levels of setup:
| Type | Runs Before | Scope |
| Test Setup | Each Test case | Individual Test |
| Suite Setup | Entire Test Suite | Whole Test Suite |
Let's use your project as an example:
tests/
├── login.robot
├── addaccounts.robot
├── Demo.robot
Suppose to open the browser before every test in login.robot. You can use Test Setup in that file like this:
Example:
You can run the whole suite like this:
| robot tests/login.robot |
Benefits of Using Setup:
- Avoid code duplication – define it once, use everywhere.
- Keep tests cleaner – test steps focus only on actual validation.
- Maintainability – update common steps in one place only.
| Element | Description |
| Test Setup | Runs before each test case |
| Suite Setup | Runs once before the test suite |
| How to define | Use Test Setup or Suite Setup in *** Settings *** |
| Typical Use | Open browser, login, navigate to start page |
| Benefits | Cleaner tests, reusable setup steps |
Test Setup vs Test Teardown
In addition to setup, you can define Test Teardown and Suite Teardown to clean up after tests finish.
Test Setup – Prepare Test
- This keyword runs before every test case in the file.
- It logs the message: Starting test case...
Test Teardown – Cleanup Test
- This keyword runs after every test case.
- It logs the message: Cleaning up test data...
Where to Use This?
This setup is especially useful when:
- You need to initialize something before each test (like opening a browser, loading test data).
- You need to clean up (like closing a browser, clearing cache, logging out).
Summary:
| Concept | Description |
| Test Suite | A group of test cases organized in files/folders |
| Test Case | A single automated test scenario |
| Test Setup | Pre-test logic for initializing the test environment |
| Suite Setup | Pre-suite logic that runs once for all test cases |
| Teardown | Cleanup logic after a test or suite |
Conclusion
Robot Framework's organization—Test Suites, Test Cases, and Test Setup—keeps test automation neat, scalable, and manageable. By organizing your project correctly, such as putting test files into folders and using setup routines, you keep your tests clean, maintainable, and efficient to run.
About Author
Divya Panchal is an ISTQB-certified QA Tester at PixelQA a Software Testing Company with expertise in both manual and automation testing. She has evolved from a trainee to a key contributor across multiple projects, consistently ensuring software quality and reliability. With a strong focus on continuous professional development, Divya is dedicated to expanding her knowledge in automation and API testing, underscoring her commitment to delivering high-quality software solutions..
