一键导入
testing-mockk
Trigger: Unit Testing. Writing unit tests using MockK (no annotations), constructor injection, and InjectingTest patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Trigger: Unit Testing. Writing unit tests using MockK (no annotations), constructor injection, and InjectingTest patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Test-driven development with red-green-refactor loop. MUST be triggered during ANY coding session involving feature implementation or bug fixes or specifications.
Evaluates skills based on discoverability, agent-friendliness, and consumption efficiency. Returns a Letter Grade (A+ to F) and actionable coaching.
Validating agent skills against the agentskills.io specification and generating compliance reports.
Trigger: Data Flow & Modules. Implementing Repositories, managing cross-module boundaries, and handling async work with Coroutines.
Trigger: Pre-Commit/Final Review. Validating code against Serenity’s 'Golden Standards' for architecture, security, performance, and testing before merging.
Trigger: Presenter Logic. Managing Moxy MVP state, Presenter lifecycle, and view delegation without @InjectPresenter.
| name | testing-mockk |
| description | Trigger: Unit Testing. Writing unit tests using MockK (no annotations), constructor injection, and InjectingTest patterns. |
Standardized mocking requires explicit initialization to avoid reflection overhead and maintain consistency.
class MyPresenterTest {
private val mockView: MyView = mockk(relaxed = true)
private val mockRepo: MyRepository = mockk(relaxed = true)
// ...
}
When testing components that rely on field injection (Activities, Fragments), use the TestModule pattern.
Extend us.nineworlds.serenity.test.InjectingTest and install your mocks.
class MyActivityTest : InjectingTest() {
private val mockPresenter: MyPresenter = mockk(relaxed = true)
override fun installTestModules() {
scope.installModules(TestModule())
}
inner class TestModule : Module() {
init {
bind(MyPresenter::class.java).toInstance(mockPresenter)
}
}
@Before
override fun setUp() {
super.setUp()
// Activity/Fragment initialization logic
}
}
Crucial for preventing state leakage between tests.
@After
fun tearDown() {
clearAllMocks()
Toothpick.reset()
}
For pure logic classes (Repositories, Use Cases), use constructor injection and standard JUnit 4.
class MyRepositoryTest {
private val mockApi: MyApi = mockk(relaxed = true)
private lateinit var repository: MyRepository
@Before
fun setUp() {
repository = MyRepository(mockApi)
}
}