# TestPartResult Internal Architecture in Google Test: How Test Outcomes Are Represented

> Understand the TestPartResult internal architecture in Google Test. Learn how its four-state Type enum and metadata represent success, non-fatal failures, fatal failures, and skipped tests.

- Repository: [Google/googletest](https://github.com/google/googletest)
- Tags: internals
- Published: 2026-08-30

---

**The `TestPartResult` class in Google Test encapsulates every assertion result using a four-state `Type` enum and metadata fields, enabling the framework to distinguish between success, non-fatal failures, fatal failures, and skipped test parts.**

The `TestPartResult` class serves as the fundamental data structure within the [google/googletest](https://github.com/google/googletest) framework for capturing the outcome of individual test parts. Whether an assertion succeeds, fails fatally, fails non-fatally, or is skipped, the framework instantiates a `TestPartResult` object to record the specific outcome along with source location and diagnostic information.

## Core Components of the TestPartResult Class

The `TestPartResult` class is defined in [`googletest/include/gtest/gtest-test-part.h`](https://github.com/google/googletest/blob/main/googletest/include/gtest/gtest-test-part.h) (lines 57-109). It combines a strongly-typed enumeration with contextual metadata to provide a complete snapshot of any assertion's execution.

### The Type Enum and Outcome Classification

At the heart of `TestPartResult` lies the **`Type`** enumeration (lines 57-64), which defines four distinct states:

- **`kSuccess`**: The assertion evaluated successfully.
- **`kNonFatalFailure`**: The assertion failed but execution continues (e.g., `EXPECT_*` macros).
- **`kFatalFailure`**: The assertion failed and aborted the current test (e.g., `ASSERT_*` macros).
- **`kSkip`**: The test part was intentionally skipped via `GTEST_SKIP()`.

The constructor (lines 66-71) captures this type alongside the source file name, line number, summary string, and full message.

### Metadata and Diagnostic Accessors

Each `TestPartResult` stores precise location and message data:

- **`file_name()`** and **`line_number()`** (lines 80-88): Return the source location, or `nullptr` and `-1` if unknown.
- **`summary()`** and **`message()`** (lines 90-94): Provide human-readable diagnostics. The summary is a truncated version generated by the static **`ExtractSummary`** helper (lines 15-16) that removes stack traces, while `message()` contains the complete diagnostic text.

### Convenience Predicates

Rather than comparing enum values directly, the class exposes boolean accessors (lines 96-109): **`passed()`**, **`failed()`**, **`nonfatally_failed()`**, **`fatally_failed()`**, and **`skipped()`**. These predicates simplify conditional logic when processing test results programmatically.

## How TestPartResult Represents Different Test Outcomes

The framework uses the `type_` field to determine flow control and reporting behavior for each test part.

**Success**: When `type_ == kSuccess`, `passed()` returns `true`. No failure message is stored, and execution proceeds to the next statement.

**Non-fatal Failure**: When `type_ == kNonFatalFailure`, both `failed()` and `nonfatally_failed()` return `true`. The test continues executing subsequent assertions, but the failure is recorded in the `TestPartResultArray`.

**Fatal Failure**: When `type_ == kFatalFailure`, `fatally_failed()` and `failed()` are `true`. The current test method terminates immediately after the `TestPartResult` is reported and stored.

**Skip**: When `type_ == kSkip`, `skipped()` returns `true`. The framework marks the test part as intentionally bypassed, recording file and line information but no failure diagnostics.

## Integration with the Google Test Framework

Individual `TestPartResult` objects do not exist in isolation; they are collected, stored, and reported through specific framework mechanisms.

### TestPartResultArray Collection

As defined in [`googletest/include/gtest/gtest-test-part.h`](https://github.com/google/googletest/blob/main/googletest/include/gtest/gtest-test-part.h) (lines 31-49), the **`TestPartResultArray`** class manages a sequence of `TestPartResult` objects. This array is owned by **`TestResult`** (declared in [`googletest/include/gtest/gtest.h`](https://github.com/google/googletest/blob/main/googletest/include/gtest/gtest.h)), which aggregates all parts for a single test case. You can query the array via `TestResult::test_part_results()` or access individual entries through `TestResult::GetTestPartResult()`.

### Reporting via TestPartResultReporterInterface

When an assertion macro executes, it creates a `TestPartResult` and dispatches it through the **`TestPartResultReporterInterface`** (lines 55-61). The default implementation, **`DefaultGlobalTestPartResultReporter`** (implemented in [`googletest/src/gtest-internal-inl.h`](https://github.com/google/googletest/blob/main/googletest/src/gtest-internal-inl.h)), receives the object via `ReportTestPartResult` and appends it to the current thread's `TestResult`. This decouples assertion evaluation from result storage, enabling custom reporters to intercept outcomes without modifying core logic.

## Practical Example: Accessing TestPartResult Objects

Below are examples demonstrating how assertions generate `TestPartResult` instances internally, and how to inspect these objects programmatically.

First, basic assertions create different outcome types automatically:

```cpp
TEST(MathTest, SimpleAssertions) {
  EXPECT_EQ(2 + 2, 4);            // Generates TestPartResult with kSuccess
  EXPECT_TRUE(false);             // Generates kNonFatalFailure (test continues)
  ASSERT_TRUE(false);             // Generates kFatalFailure (test aborts here)
  GTEST_SKIP();                   // Generates kSkip
}

```

Second, you can iterate through results to analyze outcomes programmatically:

```cpp
TEST(FailureInspection, RetrieveResults) {
  EXPECT_EQ(1, 2);                // Non-fatal failure
  EXPECT_TRUE(true);              // Success

  const ::testing::TestResult& tr = ::testing::UnitTest::GetInstance()
                                      ->current_test_info()
                                      ->result();

  for (int i = 0; i < tr.total_part_count(); ++i) {
    const ::testing::TestPartResult& r = tr.GetTestPartResult(i);
    std::cout << "Part " << i << ": "
              << (r.passed() ? "PASSED" : "FAILED")
              << " (" << r.summary() << ")\n";
  }
}

```

## Summary

- **TestPartResult** is the core value object in Google Test that captures the outcome of every individual assertion or test part.
- The **`Type` enum** defines four distinct states: `kSuccess`, `kNonFatalFailure`, `kFatalFailure`, and `kSkip`.
- Metadata fields store source location (`file_name`, `line_number`) and diagnostic messages (`summary`, `message`), with the latter processed by the **`ExtractSummary`** utility.
- Boolean predicates (**`passed()`**, **`failed()`**, **`fatally_failed()`**, etc.) provide type-safe outcome inspection.
- **`TestPartResultArray`** aggregates results within **`TestResult`**, while **`TestPartResultReporterInterface`** handles the dispatch of results to storage and output sinks.

## Frequently Asked Questions

### What are the four possible outcomes of a TestPartResult in Google Test?

The four outcomes are defined in the `Type` enum within [`gtest-test-part.h`](https://github.com/google/googletest/blob/main/gtest-test-part.h): `kSuccess` for passing assertions, `kNonFatalFailure` for failed `EXPECT_*` macros that allow execution to continue, `kFatalFailure` for failed `ASSERT_*` macros that abort the test, and `kSkip` for test parts bypassed via `GTEST_SKIP()`.

### How does Google Test distinguish between fatal and non-fatal failures?

Google Test distinguishes these through the `Type` enum value stored in `TestPartResult`. Non-fatal failures use `kNonFatalFailure`, causing `nonfatally_failed()` to return `true` while allowing the test to continue. Fatal failures use `kFatalFailure`, causing `fatally_failed()` to return `true` and triggering immediate test termination via exception-based or longjmp-based stack unwalling (platform dependent).

### Where is TestPartResult defined in the Google Test source code?

The class is defined in [`googletest/include/gtest/gtest-test-part.h`](https://github.com/google/googletest/blob/main/googletest/include/gtest/gtest-test-part.h) in the [google/googletest](https://github.com/google/googletest) repository. This header also defines the `TestPartResultArray` container and `TestPartResultReporterInterface`, while the implementation of default reporters resides in [`googletest/src/gtest-internal-inl.h`](https://github.com/google/googletest/blob/main/googletest/src/gtest-internal-inl.h).

### Can I access TestPartResult objects programmatically in my test code?

Yes. During test execution, you can obtain the current `TestResult` via `::testing::UnitTest::GetInstance()->current_test_info()->result()`, then iterate through its parts using `total_part_count()` and `GetTestPartResult(index)`. Each returned `TestPartResult` provides accessors like `passed()`, `failed()`, `file_name()`, `line_number()`, and `summary()` for inspection.