RepositorySwiftPLBa Lan
MA

Matejkob/swift-spyable

Swift macro that simplifies and automates the process of creating spies for testing

470sao
51fork
9issue
1lượt xem

🛠️ Tự động sinh spy cho protocol với @Spyable

Một macro Swift mạnh mẽ, biến bất kỳ protocol nào thành spy class chỉ bằng một chú thích — không cần viết tay.

@Spyable là một công cụ Swift giúp tự động hóa quá trình tạo các lớp tuân thủ protocol. Ban đầu được thiết kế để đơn giản hóa testing bằng cách sinh spy, nó hiện còn được dùng rộng rãi cho các trường hợp như SwiftUI previews hoặc tạo dummy implementation nhanh chóng.

✨ Điểm nổi bật

  • Sinh spy tự động: Dùng @Spyable để sinh ngay lớp spy tương ứng.
  • Kế thừa access level: Lớp sinh tự động kế thừa access level của protocol.
  • Ghi đè access level: Dùng accessLevel để thiết lập mức truy cập tùy chỉnh.
  • Theo dõi tương tác: Spy ghi nhận số lần gọi, tham số và giá trị trả về.
  • Hỗ trợ method overloading: Đặt tên duy nhất cho từng phiên bản nạp chồng.
  • Điều khiển bằng flag: Dùng behindPreprocessorFlag để giới hạn spy trong môi trường debug.

💡 Vì sao đáng chú ý

Thay vì phải thủ công viết từng spy class với hàng chục dòng mã lặp lại, @Spyable tạo ra chúng một cách nhanh chóng và chính xác. Điều này đặc biệt hữu ích trong unit testing nơi spy thường chiếm phần lớn thời gian viết code. Ngoài ra, khả năng hỗ trợ method overloading và các tùy chọn access level linh hoạt giúp dự án dễ dàng tích hợp vào nhiều ngữ cảnh khác nhau — từ testing cho đến SwiftUI previews.


#Swift #Macro #Testing #UnitTesting #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositorySwift
swiftlang/swift-testing

A modern, expressive testing package for Swift

2.2k
Dec 2, 2026
RepositoryPython
pytest-dev/pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

14.8k
Nov 30, 2026
RepositorySwift
permissionlesstech/bitchat

bluetooth mesh chat, IRC vibes

37.2k
Nov 27, 2026
RepositoryTypeScript
storybookjs/storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation

91.8k
Nov 29, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryPython
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

199.5k
Dec 2, 2026
RepositoryTypeScript
microsoft/vscode

Visual Studio Code

195.9k
Nov 30, 2026
RepositorySwift
iina/iina

The modern video player for macOS.

47.4k
Dec 1, 2026
RepositorySwift
Alamofire/Alamofire

Elegant HTTP Networking in Swift

42.4k
Nov 27, 2026