Files
firebase-ios-sdk/GeminiLanguageModel/Tests/GeminiLanguageModelTests
Andrew Heard c276eca72a refactor(ai): gate GLM Entry.data on Swift 6.4.2 (#16910)
Replace `#if canImport(FoundationModels, _version: 2.1)` with
`#if compiler(>=6.4.2)` around the `Transcript.Entry.data` case in
`GeminiTranscriptTranslator` and its test. Xcode 27.2 beta 3 bumped the
Swift compiler to 6.4.2, so the condition no longer depends on the
underscored `_version` parameter of `canImport`.

Earlier Xcode 27.2 betas report Swift 6.4 and skip the case, which is
acceptable since beta 3 supersedes them.
2026-10-14 22:34:59 -04:00
..

GeminiLanguageModel Tests

Unit and integration test suites validating GeminiLanguageModel protocol conformance, streaming response generation, transcript translation, error mapping, and backend integration.

Quick Start

# Run all unit tests (fast, ~0.04s, skips integration tests)
swift test --skip IntegrationTests

# Run all tests in this target (including integration tests)
swift test --filter GeminiLanguageModelTests

Test Suites

Suite / File Scope Strategy
GeminiLanguageModelTests.swift Protocol conformance, single/multi-turn responses, streaming, tool calling Unit (MockHTTPURLProtocol)
GenerationSchema+GeminiTests.swift JSON Schema encoding and property ordering conversion Unit (pure transformation)
GeminiRequestTranslatorTests.swift Request, generation config, tool declarations, and tool mode mapping Unit (pure transformation)
GeminiTranscriptTranslatorTests.swift Apple Transcript <-> Gemini payload mapping (tools, reasoning, prompts) Unit (pure transformation)
GeminiErrorMapperTests.swift HTTP and API error mapping to LanguageModelError Unit (exhaustive mapping)
IntegrationTestingBackendTests.swift Endpoint resolution and credential discovery Unit / Infrastructure
IntegrationTests/ End-to-end Gemini and Firebase AI Logic integration tests Integration (see IntegrationTests/README.md)

Testing Architecture

This target separates tests into two distinct tiers:

  1. Unit Tests (Default):

    • Use MockHTTPURLProtocol for deterministic, zero-network, sub-second execution.
    • Run cleanly in offline, CI, and local development environments without any credentials or background daemons.
  2. Integration Tests (IntegrationTests/):

    • Tagged with .tags(.integration) and gated by .requireIntegrationTestingBackend.
    • Exercise endpoints on Google Cloud and Firebase using configured credentials.
    • Isolated in the IntegrationTests/ subfolder so unit test runs are never slowed down by network timeouts or external dependencies.

Tip

For details on configuring credentials and parameterizing integration tests, see the Integration Tests Guide.