测试助手
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- 写作
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- 无特殊要求
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: bcsc-core-native-testing
description: Create native unit tests for Swift (iOS) and Kotlin (Android) code in the bcsc-core package. USE…
category: 写作
runtime: 无特殊运行时
---
# bcsc-core-native-testing 输出预览
## PART A: 任务判断
- 适用问题:文章、文案、发言稿、润色或结构化表达。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Overview / Test Infrastructure / iOS — XCTest via SPM”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于文章、文案、发言稿、润色或结构化表达,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Overview / Test Infrastructure / iOS — XCTest via SPM”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件。
先用一个小任务确认它会围绕“Overview / Test Infrastructure / iOS — XCTest via SPM”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: bcsc-core-native-testing
description: Create native unit tests for Swift (iOS) and Kotlin (Android) code in the bcsc-core package. USE…
category: 写作
source: tomevault-io/skills-registry
---
# bcsc-core-native-testing
## 什么时候使用
- 用于组织测试、定位失败并形成修复闭环 适合处理文章、文案、润色、翻译、总结和结构化表达,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤;通常不需要额外 AP…
- 面向文章、文案、发言稿、润色或结构化表达,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Overview / Test Infrastructure / iOS — XCTest via SPM」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "bcsc-core-native-testing" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Overview / Test Infrastructure / iOS — XCTest via SPM
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> 无特殊运行时 | 读取文件、写入/修改文件 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} bcsc-core Native Unit Testing
Overview
This skill guides creation of native unit tests for the packages/bcsc-core module, which contains Swift (iOS) and Kotlin (Android) implementations of authentication, PIN management, keychain storage, token services, and device authentication.
The codebase already uses protocol-based dependency injection on iOS and interface/class-based injection on Android, making it straightforward to create mock implementations for isolated unit testing.
Test Infrastructure
iOS — XCTest via SPM
Tests are built with Swift Package Manager using the package manifest at packages/bcsc-core/Package.swift. The key concepts:
BcscCoreTestabletarget: A subset of production iOS source files compiled for the simulator (without React Native / CocoaPods dependencies). Only files listed in thesources:array are included.BcscCoreTeststest target: XCTest files underios/BcscCoreTests/, compiled with@testable import BcscCoreTestable.SPM_BUILDflag: A Swift compiler define set inPackage.swiftviaswiftSettings: [.define("SPM_BUILD")]. The fileios/SPMCompat.swiftuses#if SPM_BUILDto provide lightweight stubs (e.g.,SecureRandom,Data.arrayOfBytes()) for types from JWE files that aren't included in the SPM target.- Scheme name: xcodebuild uses
BcscCoreTests-Package(SPM auto-appends-Package).
Adding a new iOS source file to the test target
If the code under test references types in a file not yet in Package.swift, add it to the sources: array in the BcscCoreTestable target. If that file depends on types from excluded files (e.g., JWE/crypto), add stubs to SPMCompat.swift behind #if SPM_BUILD.
Adding a new iOS test file
- Create a new
.swiftfile inios/BcscCoreTests/. - Import frameworks and the testable module:
import LocalAuthentication // if testing LAPolicy/biometric types import XCTest @testable import BcscCoreTestable - Write
XCTestCasesubclasses. Follow the naming convention{ClassUnderTest}Tests. - Run with
yarn test:iosor directly:xcodebuild test -scheme BcscCoreTests-Package \ -destination 'platform=iOS Simulator,name=iPhone 16,OS=latest' \ -skipPackagePluginValidation
Android — JUnit 4 + MockK
Tests live under android/src/test/java/com/bcsccore/ mirroring the main source package structure.
Dependencies (in android/build.gradle)
testImplementation 'junit:junit:4.13.2'
testImplementation 'io.mockk:mockk:1.13.8'
testImplementation 'org.robolectric:robolectric:4.11.1'
testImplementation 'androidx.test:core:1.5.0'
Adding a new Android test file
- Create a Kotlin file in
android/src/test/java/com/bcsccore/{subpackage}/, matching the source package. - Write standard JUnit 4 test classes with
@Testmethods. - Use
io.mockk.mockk<T>()andevery { ... } returns ...for mocking. - Run with
yarn test:androidor directly:cd android && ./gradlew test
Running all tests
yarn test # runs test:ios then test:android
yarn test:ios # iOS only
yarn test:android # Android only
Mocking Strategy
iOS — Protocol Conformance
The codebase defines protocols for all service boundaries. Create mock classes that conform to the protocol and expose controllable properties:
final class MockPINService: PINServiceProtocol {
var verifyResult: String? // control return value
var setPINResult: String = "mock-hash"
var deletePINCalled = false // track side effects
func verifyPINAndGetHash(issuer _: String, accountID _: String, pin _: String) -> String? {
return verifyResult
}
func setPIN(issuer _: String, accountID _: String, pin _: String, isAutoGenerated _: Bool) throws -> String {
return setPINResult
}
func deletePIN(issuer _: String, accountID _: String) throws {
deletePINCalled = true
}
// ... remaining protocol methods
}
Pattern: Use var resultProperty for controlling return values and var methodCalled = false booleans for verifying side effects.
Available iOS protocols for mocking
| Protocol | File | Purpose |
|---|---|---|
PINServiceProtocol |
PINServiceProtocol.swift |
PIN set/verify/delete/hash |
PINKeychainServiceProtocol |
PINKeychainService.swift |
Keychain secret storage |
PINCryptoPolicyProtocol |
PINCryptoPolicy.swift |
Salt/key/iteration config |
CommonCryptoWrapperProtocol |
CommonCryptoWrapper.swift |
PBKDF2 key derivation |
LAContextProtocol |
LAContext+Extensions.swift |
Biometric evaluation |
DeviceAuthServiceProtocol |
DeviceAuthService.swift |
Device authentication |
TokenStorageServiceProtocol |
TokenService.swift |
Token keychain storage |
KeyPairManagerProtocol |
KeyPairManager.swift |
Cryptographic key pairs |
Android — MockK
Use MockK's mockk<T>() for mocking classes and interfaces:
val mockPinService = mockk<PinService>()
every { mockPinService.validatePIN(any(), "1234") } returns true
every { mockPinService.hasPIN(any()) } returns true
val account = Account(id = "test", issuer = "https://idsit.gov.bc.ca", clientID = "client")
val result = account.verifyPIN("1234", mockPinService)
assertTrue(result.success)
For data classes (e.g., NativeAccount), test serialization round-trips with Gson directly — no mocking needed.
Test Patterns
Time-dependent tests (eg. PIN penalty logic)
The penalty system locks users out after failed PIN attempts. Both platforms accept an injectable "current time" parameter to make tests deterministic.
iOS: Pass verifyDate: parameter:
let start = Date()
for i in 0..<5 {
_ = account.verifyPIN("wrong", pinService: mock, verifyDate: start.addingTimeInterval(Double(i)))
}
// Advance past penalty before next batch
let afterPenalty = start.addingTimeInterval(65)
Android: Pass timestamp to verifyPIN and isServingPenalty:
val now = System.currentTimeMillis()
account.verifyPIN("wrong", mockPinService, now)
val penalty = account.isServingPenalty(now)
Important: When testing escalating penalties, you must advance time past each penalty tier before triggering the next. Calling verifyPIN while a penalty is active will return "locked" without incrementing the attempt counter.
Penalty tiers: 5 attempts → 1 min, 10 → 10 min, 15 → 1 hour, 20 → 1 day.
NSCoding / Serialization round-trips
iOS — Use NSKeyedArchiver / NSKeyedUnarchiver:
let data = try NSKeyedArchiver.archivedData(withRootObject: original, requiringSecureCoding: true)
let decoded = try NSKeyedUnarchiver.unarchivedObject(ofClass: Account.self, from: data)
XCTAssertEqual(decoded?.id, original.id)
Android — Use Gson:
val json = gson.toJson(original)
val restored = gson.fromJson(json, NativeAccount::class.java)
assertEquals(original.uuid, restored.uuid)
Test naming conventions
iOS: test{Behavior} in camelCase — e.g., testVerifyPINReturnsSuccessOnCorrectPIN
Android: Backtick-quoted descriptive names — e.g., `verifyPIN returns success when PIN is correct`
Helper factories
Android — Create a createAccount() helper with defaults to reduce boilerplate:
private fun createAccount(
id: String = "test-uuid",
issuer: String = "https://idsit.gov.bc.ca",
clientID: String = "test-client-id",
securityMethod: AccountSecurityMethod = AccountSecurityMethod.PIN_NO_DEVICE_AUTH,
): Account = Account(id = id, issuer = issuer, clientID = clientID, securityMethod = securityMethod)
Checklist for adding tests
- Identify the class/struct to test and which platform(s)
- Check if the source file is already in
Package.swiftsources:(iOS) — add if missing - Check if new dependencies need stubs in
SPMCompat.swift(iOS) - Create mock(s) for any protocol/interface dependencies
- Place test file in
ios/BcscCoreTests/orandroid/src/test/java/com/bcsccore/{subpackage}/ - For time-dependent logic, use injectable timestamps rather than
Date()/System.currentTimeMillis() - Run
yarn testand verify all tests pass on both platforms
Source: bcgov/bc-wallet-mobile — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核