create-tests-swift

create-tests-swift is a cursor rule for Cursor from brunogama/ios-cursor-rules. It costs 2,570 tokens per session, scanned A, original, MIT.

A guide to writing unit tests for Swift code, with naming rules and the Arrange-Act-Assert structure: set up the test, perform the action, then check the result. Unit tests check small pieces of a program separately.

In plain words
What is it for?
Use it when adding or reviewing Swift unit tests for functions, classes, valid and invalid inputs, and expected errors or results.
Why use it?
It provides a consistent way to test every public function and makes test failures easier to understand and maintain.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/brunogama/ios-cursor-rules/create-tests-swift
Clone the repo
git clone --depth 1 https://github.com/brunogama/ios-cursor-rules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for create-tests-swift

README.md
[![agentmods](https://agentmods.dev/badge/rules/brunogama/ios-cursor-rules/create-tests-swift.svg)](https://agentmods.dev/rules/brunogama/ios-cursor-rules/create-tests-swift)
Your own site
<a href="https://agentmods.dev/rules/brunogama/ios-cursor-rules/create-tests-swift"><img src="https://agentmods.dev/badge/rules/brunogama/ios-cursor-rules/create-tests-swift.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,570 This file is loaded in full into every session.
When invoked 2,570 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02570 $0.02570
Opus 5 $0.01285 $0.01285
Sonnet 5 $0.00514 $0.00514
Haiku 4.5 $0.00257 $0.00257

Measured 3d ago against content hash d3f32ab03cd7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

create-tests-swift scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/create-tests-swift.mdc · 403 lines

How it starts

The opening of the file, as written. The whole thing — 403 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Swift Testing Guide

This guide outlines Swift testing principles and practices, focusing on creating effective unit tests for Swift code.

actions:

  • type: suggest message: |

    Swift Testing Guidelines

    In this project, every public function must have unit tests. We follow these guidelines:

    Test Structure

    Naming Convention
    • Test class name: [ClassUnderTest]Tests
    • Test method name: test_[FunctionUnderTest]_[Scenario]_[ExpectedResult]

    Example:

    class UserAuthenticationTests: XCTestCase {
        func test_authenticate_withValidCredentials_shouldReturnToken() { ... }
        func test_authenticate_withInvalidPassword_shouldThrowAuthError() { ... }
    }
    
    Arrangement

    Every test should follow the Arrange-Act-Assert (AAA) pattern:

    func test_addItem_withValidProduct_shouldAddToCart() {
        // Arrange
        let cart = ShoppingCart(id: CartID())
        let product = Product(id: ProductID(), name: "Test Product", price: Money(amount: 10, currency: .usd))
        
        // Act
        try! cart.addItem(product: product, quantity: 1)
        
        // Assert
        XCTAssertEqual(cart.items.count, 1)
        XCTAssertEqual(cart.total()?.amount, 10)
    }
    

    Types of Tests

    1. Unit Tests
    • Tests a single unit of code in isolation
    • Uses mocks/stubs for dependencies
    • Fast and reliable
    • Located in target's matching test target (e.g., DomainTests for Domain code)
    func test_placeOrder_withValidItems_shouldCreateOrderSuccessfully() {
        // Arrange
        let mockOrderRepository = MockOrderRepository()
        let mockProductRepository = MockProductRepository()
        let orderService = OrderService(
            orderRepository: mockOrderRepository,
            productRepository: mockProductRepository
        )
        
        let items = [OrderItem(productID: ProductID(), quantity: 1, price: Money(amount: 10, currency: .usd))]
        
        // Act
        let result = orderService.placeOrder(items: items, customerID: CustomerID())
        
        // Assert
        XCTAssertTrue(result.isSuccess)
        XCTAssertEqual(mockOrderRepository.savedOrders.count, 1)
    }
    
    2. Integration Tests
    • Tests interaction between multiple components
    • Typically involves real implementations rather than mocks
    • Located in separate test targets
    func test_orderFlow_endToEnd_shouldProcessOrderSuccessfully() {
        // Tests the full order flow from cart to confirmation
        // Uses real implementations for most components
    }
    

    Mocking Guidelines

    • Create mocks for protocols, not for concrete classes
    • Use protocol-based dependencies to make testing easier
    • Name mocks clearly with the Mock prefix
    protocol OrderRepository {
        func save(_ order: Order) throws
        func findByID(_ id: OrderID) -> Order?
    }
    
    class MockOrderRepository: OrderRepository {
        var savedOrders: [Order] = []
        var ordersToReturn: [OrderID: Order] = [:]
        
        func save(_ order: Order) throws {
            savedOrders.append(order)
        }
        
        func findByID(_ id: OrderID) -> Order? {
            return ordersToReturn[id]
        }
    }
    

    Testing Value Objects

    Test both valid and invalid initialization:

    func test_emailInitialization_withValidEmail_shouldSucceed() {
        // Arrange & Act
        let email = Email(value: "[email protected]")
        
        // Assert
        XCTAssertNotNil(email)
        XCTAssertEqual(email?.value, "[email protected]")
    }
    
    func test_emailInitialization_withInvalidEmail_shouldReturnNil() {
        // Arrange & Act
        let email = Email(value: "invalid-email")
        
        // Assert
        XCTAssertNil(email)
    }
    

Read the full file on GitHub · 403 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 403 lines · 2,570 tokens per session scan A d3f32ab03cd7

Subscribe to this mod's changes

create-tests-swift is a cursor rule published in the GitHub repository brunogama/ios-cursor-rules (74 stars, last pushed 1y ago), licensed MIT. It adds 2,570 tokens to every session, about $0.0128 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.