Skip to content

iOS: All unit tests are unimplemented TODOs - 0% test coverage #48

@sfloess

Description

@sfloess

Description

All iOS unit tests in NexusClientURLSessionTests.swift are stub methods with TODO comments. No actual test logic has been implemented, resulting in 0% test coverage for iOS code.

Problem Location

jnexus-ios/Tests/Shared/NexusClientURLSessionTests.swift

All 8 test methods are TODOs:

  • testCacheHit() - line 29
  • testCacheMiss() - line 37
  • testCacheExpiry() - line 44
  • testRetryOnTimeout() - line 54
  • testNoRetryOn4xx() - line 61
  • testPagination() - line 70
  • testParseBasicResponse() - line 79
  • testParseMetadataResponse() - line 86

Impact

  • Zero coverage: iOS HTTP client has no automated tests
  • Regressions: Changes can break functionality without detection
  • Platform parity: Android has 13 tests, Desktop has 155 tests, iOS has 0 real tests
  • Trust: Cannot confidently release iOS app without test coverage
  • Maintenance: Refactoring is risky without safety net

Test Implementation Blockers

The TODO comments mention needing URLProtocol mocking, which suggests the tests require:

  1. Mock URLSession responses
  2. Network interception/stubbing
  3. Time mocking for cache expiry tests

Recommended Approach

Use URLProtocol for network mocking:

class MockURLProtocol: URLProtocol {
    static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data))?
    
    override class func canInit(with request: URLRequest) -> Bool {
        true
    }
    
    override class func canonicalRequest(for request: URLRequest) -> URLRequest {
        request
    }
    
    override func startLoading() {
        guard let handler = MockURLProtocol.requestHandler else {
            fatalError("Handler not set")
        }
        
        do {
            let (response, data) = try handler(request)
            client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
            client?.urlProtocol(self, didLoad: data)
            client?.urlProtocolDidFinishLoading(self)
        } catch {
            client?.urlProtocol(self, didFailWithError: error)
        }
    }
    
    override func stopLoading() {}
}

Example test implementation:

func testCacheHit() async throws {
    // Configure mock
    let config = URLSessionConfiguration.ephemeral
    config.protocolClasses = [MockURLProtocol.self]
    
    MockURLProtocol.requestHandler = { request in
        let response = HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: nil, headerFields: nil)!
        let json = "{\"items\": [], \"continuationToken\": null}"
        return (response, json.data(using: .utf8)!)
    }
    
    // Test cache hit
    let client = NexusClientURLSession(credentials: credentials, session: URLSession(configuration: config))
    
    _ = try await client.listComponents(repository: "test", forceRefresh: false)
    XCTAssertTrue(client.isCached("test"))
    
    _ = try await client.listComponents(repository: "test", forceRefresh: false)
    // Second call should use cache, not make HTTP request
}

Priority

High - iOS app has zero automated testing

Related

Acceptance Criteria

  • All 8 test methods fully implemented
  • URLProtocol mocking infrastructure in place
  • Tests verify caching behavior
  • Tests verify retry logic
  • Tests verify pagination
  • Tests verify JSON parsing
  • CI runs iOS tests automatically

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions