test-driven-development
Skill2 starsChanged 40 days agoMITView on GitHub
Use when implementing new features or fixing bugs. Write tests before implementation following Red-Green-Refactor. Covers JUnit5, MockK, Compose test rules, and the Prove-It pattern for bugs.
190 other projects use a version of this.
Adopted by
Most recently taken up by
- DemonDamon/AgenticXtheir own version, first seen Nov 9, 2026
- chrysogonus/power-agentstheir own version, first seen Nov 8, 2026
- ishandutta2007/Awesome-Agent-Skillstheir own version, first seen Nov 8, 2026
- roundpilot/superpowers-antigravitytheir own version, first seen Nov 8, 2026
- REPOZY/superpowers-optimizedtheir own version, first seen Nov 8, 2026
- lingyired/status-triotheir own version, first seen Nov 8, 2026
Used with
Projects with it also use chinese-code-review, chinese-commit-conventions and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
Leodorareluctant259Skillchinese-code-review
中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈
Also in 8 projects that use this
Leodorareluctant259Skillchinese-commit-conventions
中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化
Also in 8 projects that use this
obraSkilldiagnosing-superpowers
Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.
Also in 19 projects that use this
- +3 more from Leodorareluctant259
Other versions190 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 190
- obra/superpowers★ 314ksame name
- NousResearch/hermes-agent★ 262ksame name
- addyosmani/agent-skills★ 114ksame name
- cloudflare/computer★ 9.9ksame name
- jnMetaCode/superpowers-zh★ 8.4ksame name
- openai/plugins★ 7.8ksame name
- farm-fe/farm★ 5.6ksame name
- microsoft/FluidFramework★ 4.9ksame name
- mikeyobrien/ralph-orchestrator★ 3.2ksame name
- crbnos/carbon★ 2.8ksame name
180 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- android-accessibilitySkill
- android-architectureSkill
- android-background-workSkill
- android-data-persistenceSkill
- android-device-testingSkill
- android-e2e-verificationSkill
- android-ui-engineeringSkill
- api-and-interface-designSkill
- ci-cd-and-automationSkill
- code-review-and-qualitySkill
- code-simplificationSkill
- constraint-driven-developmentSkill
- context-engineeringSkill
- debugging-and-error-recoverySkill
- deprecation-and-migrationSkill
- documentation-and-adrsSkill
- doubt-driven-developmentSkill
- git-workflow-and-versioningSkill
- idea-refineSkill
- incremental-implementationSkill
- interview-meSkill
- observability-and-instrumentationSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- security-and-hardeningSkill
- shipping-and-launchSkill
- source-driven-developmentSkill
- spec-driven-developmentSkill
- using-agent-skillsSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 5 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 178 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Write tests before implementation.
- Distinctive: line 20
Before refactoring (establish a test safety net first)
- Distinctive: line 72
If it passes immediately, the test doesn't test what you think
- Distinctive: line 100
Run tests after every change
- Distinctive: line 252
No tests for error/edge cases
“Common” is measured: kept by at least 6 in 10 of the 178 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test-Driven Development
Overview
Write tests before implementation. The Red-Green-Refactor cycle — write a failing test (RED), write minimal code to pass (GREEN), improve the code without changing behavior (REFACTOR) — produces code that is correct by construction and has comprehensive test coverage from the start.
When to Use
- Implementing any new feature or behavior
- Fixing any bug (use the Prove-It pattern)
- Adding new business logic to ViewModels, use cases, or repositories
- Before refactoring (establish a test safety net first)
Skip when: Purely cosmetic UI changes with no behavioral logic.
Core Process
Red-Green-Refactor Cycle
RED: Write a Failing Test
- Write the test first — describe what the code should do:
class TaskListViewModelTest {
private val repository = mockk<TaskRepository>()
private lateinit var viewModel: TaskListViewModel
@Test
fun `initial state is Loading`() {
every { repository.getTasks() } returns flowOf(emptyList())
viewModel = TaskListViewModel(GetTasksUseCase(repository))
assertEquals(TaskListUiState.Loading, viewModel.uiState.value)
}
@Test
fun `emits Success with tasks when repository returns data`() = runTest {
val tasks = listOf(Task("1", "Buy groceries", false))
every { repository.getTasks() } returns flowOf(tasks)
viewModel = TaskListViewModel(GetTasksUseCase(repository))
advanceUntilIdle()
assertEquals(TaskListUiState.Success(tasks), viewModel.uiState.value)
}
@Test
fun `emits Error when repository throws`() = runTest {
every { repository.getTasks() } returns flow { throw IOException("Network error") }
viewModel = TaskListViewModel(GetTasksUseCase(repository))
advanceUntilIdle()
val state = viewModel.uiState.value
assertIs<TaskListUiState.Error>(state)
assertEquals("Network error", state.message)
}
}- Run the test — it must fail (
./gradlew test)- If it passes immediately, the test doesn't test what you think
GREEN: Write Minimal Code to Pass
- Implement just enough to make the test pass:
@HiltViewModel
class TaskListViewModel @Inject constructor(
getTasks: GetTasksUseCase,
) : ViewModel() {
val uiState: StateFlow<TaskListUiState> = getTasks()
.map<List<Task>, TaskListUiState> { TaskListUiState.Success(it) }
.catch { emit(TaskListUiState.Error(it.message ?: "Unknown error")) }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), TaskListUiState.Loading)
}- Run the test — it must pass
- Don't add code "you'll need later" — only what the test demands
REFACTOR: Improve Without Changing Behavior
- Clean up while tests stay green:
- Extract common patterns
- Improve naming
- Reduce duplication
- Run tests after every change
The Prove-It Pattern (Bug Fixes)
- For every bug, prove it exists before fixing:
// Step 1: Write a test that demonstrates the bug
@Test
fun `completed tasks should not appear in active filter`() {
val tasks = listOf(
Task("1", "Active task", completed = false),
Task("2", "Done task", completed = true),
)
every { repository.getTasks() } returns flowOf(tasks)
viewModel = TaskListViewModel(GetTasksUseCase(repository))
viewModel.setFilter(TaskFilter.ACTIVE)
advanceUntilIdle()
val state = viewModel.uiState.value as TaskListUiState.Success
assertEquals(1, state.tasks.size)
assertEquals("Active task", state.tasks[0].title)
}
// Step 2: Run it — confirm it FAILS (proves the bug exists)
// Step 3: Fix the code
// Step 4: Run it — confirm it PASSES (proves the fix works)
// Step 5: Run full suite — no regressionsTest Pyramid
/‾‾‾‾‾‾‾‾‾\
/ UI Tests \ ~5% — Compose rules, Espresso, Maestro flows
/ (device) \ see: android-device-testing, android-e2e-verification
/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\
/ Integration Tests \ ~15% — Room in-memory DB, MockWebServer,
| (local/device) | Robolectric
|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
| Unit Tests | ~80% — JUnit5 + MockK
| (fast, local) | ViewModels, UseCases, Repositories
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾Testing Patterns by Layer
- ViewModel tests:
@OptIn(ExperimentalCoroutinesApi::class)
class ViewModelTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule() // Sets Dispatchers.Main to TestDispatcher
@Test
fun `action updates state correctly`() = runTest {
// Arrange
val viewModel = createViewModel()
// Act
viewModel.onEvent(TaskListEvent.ToggleTask("1"))
advanceUntilIdle()
// Assert
val state = viewModel.uiState.value
// ...assertions...
}
}- Repository tests (integration):
class TaskRepositoryTest {
private val dao = mockk<TaskDao>()
private val api = mockk<TaskApi>()
private val mapper = TaskMapper()
private val repository = TaskRepositoryImpl(dao, api, mapper)
@Test
fun `syncTasks fetches from API and saves to database`() = runTest {
val apiTasks = listOf(TaskResponse("1", "Test"))
coEvery { api.getTasks() } returns apiTasks
coEvery { dao.upsertAll(any()) } just Runs
repository.syncTasks()
coVerify { dao.upsertAll(match { it.size == 1 && it[0].id == "1" }) }
}
}- Room DAO tests:
@RunWith(AndroidJUnit4::class)
class TaskDaoTest {
private lateinit var db: AppDatabase
private lateinit var dao: TaskDao
@Before
fun setup() {
db = Room.inMemoryDatabaseBuilder(
ApplicationProvider.getApplicationContext(),
AppDatabase::class.java,
).build()
dao = db.taskDao()
}
@After
fun teardown() { db.close() }
@Test
fun upsert_and_observe_returns_task() = runTest {
val task = TaskEntity("1", "Test", null, false)
dao.upsert(task)
val result = dao.observeAll().first()
assertEquals(1, result.size)
assertEquals("Test", result[0].title)
}
}Best Practices
- State over interactions — assert on outcomes, not method calls
- DAMP over DRY — each test should be self-contained and readable
- Prefer real > fakes > stubs > mocks — mock only at system boundaries
- Descriptive names — test names read like behavior specifications
- Use
runTest— for coroutine testing withTestDispatcher - Use
advanceUntilIdle()— notdelay()orThread.sleep()
Common Rationalizations
| Shortcut | Why It Fails |
| "I'll write tests after the code works" | You won't. And tests written after are weaker — they verify what you built, not what you intended. |
| "TDD is slow" | TDD prevents debugging. Net time is less. |
| "This is too simple to test" | Simple code becomes complex code. Tests catch the transition. |
| "Mocking is too complex for this" | If it's hard to mock, the design has too many dependencies. TDD surfaces this. |
| "The test passed on the first try, so it's good" | A test that never failed may not test what you think. Make it fail first. |
Red Flags
- Code written before tests
- Tests that pass immediately (never saw RED)
Thread.sleepor hardcoded delays in tests- Tests that depend on execution order
- Mocking internal classes (mock boundaries only)
- No tests for error/edge cases
@Ignoreor@Disabledtests without issue references
Verification
- Tests written BEFORE implementation (Red-Green-Refactor)
- Every test seen failing before passing
- Bug fixes use the Prove-It pattern
./gradlew testpasses (all unit tests)- Test names describe behavior, not implementation
- No
Thread.sleepin tests (useadvanceUntilIdle) - Test pyramid proportions reasonable (~80/15/5)
- Edge cases and error paths covered
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

