Skip to main content

Overview

Dolphin uses Google Test (gtest) as its unit testing framework. The test suite helps ensure code quality and prevent regressions across the emulator’s various components.

Test Organization

Tests are organized in the Source/UnitTests/ directory by component:

Running Tests

Build and Execute

Running Specific Tests

Writing Unit Tests

Test Structure

Dolphin tests use the standard Google Test macros and structure:

Common Test Patterns

Real-World Example

Here’s an actual test from Source/UnitTests/Common/BitFieldTest.cpp:

Test Categories

Common Component Tests

Tests for utility classes and common functionality:
  • BitField: Bitfield manipulation (BitFieldTest.cpp)
  • StringUtil: String operations (StringUtilTest.cpp)
  • MathUtil: Mathematical utilities (MathUtilTest.cpp)
  • FileUtil: File system operations (FileUtilTest.cpp)
  • Crypto: Cryptographic functions (SHA1Test.cpp, EcTest.cpp)
  • Threading: Thread synchronization primitives (MutexTest.cpp, EventTest.cpp)

Core Emulation Tests

Tests for CPU, memory, and system emulation:
  • PowerPC: CPU instruction tests (DivUtilsTest.cpp)
  • JIT: JIT compiler tests (Fres.cpp, Frsqrte.cpp, FPRF.cpp)
  • IOS: IOS filesystem and USB emulation (FileSystemTest.cpp, SkylandersTest.cpp)
  • DSP: DSP assembly and acceleration (DSPAssemblyTest.cpp, DSPAcceleratorTest.cpp)
  • Memory: Memory management (PageFaultTest.cpp, MMIOTest.cpp)

Video Tests

Tests for graphics rendering components:
  • VertexLoader: Vertex data processing (VertexLoaderTest.cpp)

Adding New Tests

1

Create test file

Create a new .cpp file in the appropriate directory under Source/UnitTests/:
2

Update CMakeLists.txt

Add your test file to the appropriate CMakeLists.txt:
3

Build and run

Build and verify your tests pass:

Test Framework Details

Main Test Harness

The test suite is initialized in UnitTestsMain.cpp:
The custom message handler prevents tests from breaking on assertions by automatically returning “yes” to any questions.

CMake Integration

The test build system is configured in Source/UnitTests/CMakeLists.txt:

Best Practices

1

Test one thing

Each test should verify a single aspect of functionality:
2

Use descriptive names

Test names should clearly describe what is being tested:
3

Prefer EXPECT over ASSERT

Use EXPECT_* instead of ASSERT_* to continue testing after failures:
Only use ASSERT_* when continuing after a failure would cause crashes.
4

Test edge cases

Include boundary conditions and error cases:
5

Keep tests fast

Unit tests should run quickly. Avoid slow operations or use test fixtures to share expensive setup.
6

Make tests independent

Tests should not depend on each other or on execution order.
Always run the full test suite before submitting a pull request to ensure your changes don’t break existing functionality.

Continuous Integration

Dolphin’s CI system automatically runs all tests on every pull request. Tests must pass before code can be merged.

Next Steps

Code Style

Review C++ coding standards

Debugging

Learn debugging techniques