Annotate your Testcases
This guide shows you how to annotate your tests with Allure metadata and organize them with steps.
Test Group Metadata
Section titled “Test Group Metadata”Test group (suite) metadata applies to all tests within that group. The approach differs between GoogleTest and CppUTest.
Use SetUpTestSuite() to configure suite-level metadata:
class CalculatorTests : public ::testing::Test {
protected:
static void SetUpTestSuite() {
suite()
.name("Calculator Test Suite")
.description("Tests for basic arithmetic operations")
.epic("Calculator Module")
.severity("critical");
}
};Use the setup() method in your test group:
TEST_GROUP(CalculatorTests)
{
void setup() override
{
suite()
.name("Calculator Test Suite")
.description("Tests for basic arithmetic operations")
.epic("Calculator Module")
.severity("critical");
}
};Test Metadata
Section titled “Test Metadata”Call test() at the start of each test to set test-specific metadata like name, feature, and story.
TEST_F(CalculatorTests, AdditionTest) {
test()
.name("Verify addition of two numbers")
.feature("Arithmetic Operations")
.story("User can add two numbers")
.severity("critical");
int result = 2 + 3;
EXPECT_EQ(5, result);
}TEST(CalculatorTests, AdditionTest)
{
test()
.name("Verify addition of two numbers")
.feature("Arithmetic Operations")
.story("User can add two numbers")
.severity("critical");
int result = 2 + 3;
CHECK_EQUAL(5, result);
}Use the step() function to organize test logic into named steps that appear in the Allure report. Steps accept a lambda function and automatically manage their lifecycle.
TEST_F(CalculatorTests, MultiStepTest) {
test()
.name("Multi-step calculation")
.feature("Arithmetic Operations");
int result = 0;
step("Initialize value to 5", [&]() {
result = 5;
});
step("Add 3 to value", [&]() {
result += 3;
});
step("Verify result is 8", [&]() {
EXPECT_EQ(8, result);
});
}TEST(CalculatorTests, MultiStepTest)
{
test()
.name("Multi-step calculation")
.feature("Arithmetic Operations");
int result = 0;
step("Initialize value to 5", [&]() {
result = 5;
});
step("Add 3 to value", [&]() {
result += 3;
});
step("Verify result is 8", [&]() {
CHECK_EQUAL(8, result);
});
}Alternative Step Syntax
Section titled “Alternative Step Syntax”You can also use RAII-style steps without lambdas:
TEST_F(CalculatorTests, RAIIStyleSteps) {
test().name("RAII-style steps example");
int result = 0;
{
auto s = step("Initialize value");
result = 5;
}
{
auto s = step("Multiply by 2");
result *= 2;
}
EXPECT_EQ(10, result);
}TEST(CalculatorTests, RAIIStyleSteps)
{
test().name("RAII-style steps example");
int result = 0;
{
auto s = step("Initialize value");
result = 5;
}
{
auto s = step("Multiply by 2");
result *= 2;
}
CHECK_EQUAL(10, result);
}Available Metadata
Section titled “Available Metadata”Suite-level
Section titled “Suite-level”.name(string)- Suite name.description(string)- Suite description.epic(string)- Epic classification.severity(string)- Severity level: “blocker”, “critical”, “normal”, “minor”, “trivial”.label(key, value)- Custom label
Test-level
Section titled “Test-level”.name(string)- Test name.description(string)- Test description.feature(string)- Feature classification.story(string)- User story.severity(string)- Severity level.label(key, value)- Custom label.flaky()- Mark test as flaky.known()- Mark test as known issue.muted()- Mark test as muted