docs(zh-CN): translate code block(plain text) (#753)

Co-authored-by: neo <neo.dowithless@gmail.com>
This commit is contained in:
zdoc.app
2026-03-23 06:39:24 +08:00
committed by GitHub
parent fd2a8edb53
commit 4f6f587700
118 changed files with 1807 additions and 1835 deletions

View File

@@ -28,21 +28,21 @@ description: 为Kotlin强制执行TDD工作流程。首先编写Kotest测试
## TDD 循环
```
RED -> Write failing Kotest test
GREEN -> Implement minimal code to pass
REFACTOR -> Improve code, tests stay green
REPEAT -> Next test case
RED -> 编写失败的 Kotest 测试
GREEN -> 实现最小化代码以通过测试
REFACTOR -> 改进代码,测试保持通过状态
REPEAT -> 进入下一个测试用例
```
## 示例会话
````text
User: /kotlin-test I need a function to validate user registration requests
用户:/kotlin-test 我需要一个验证用户注册请求的函数
Agent:
# TDD Session: Registration Validator
代理:
# TDD 会话:注册验证器
## Step 1: Define Interface
## 第一步:定义接口
```kotlin
// validator/RegistrationValidator.kt
@@ -64,7 +64,7 @@ fun validateRegistration(request: RegistrationRequest): ValidationResult {
}
```
## Step 2: Write Kotest Tests (RED)
## 第二步:编写 Kotest 测试(RED
```kotlin
// validator/RegistrationValidatorTest.kt
@@ -141,7 +141,7 @@ class RegistrationValidatorTest : FunSpec({
})
```
## Step 3: Run Tests - Verify FAIL
## 第三步:运行测试 - 验证失败
```bash
$ ./gradlew test
@@ -152,9 +152,9 @@ RegistrationValidatorTest > valid registration returns Valid FAILED
FAILED (5 tests, 0 passed, 5 failed)
```
Tests fail as expected (NotImplementedError).
测试按预期失败(NotImplementedError)。
## Step 4: Implement Minimal Code (GREEN)
## 第四步:实现最小代码(GREEN
```kotlin
// validator/RegistrationValidator.kt
@@ -175,7 +175,7 @@ fun validateRegistration(request: RegistrationRequest): ValidationResult {
}
```
## Step 5: Run Tests - Verify PASS
## 第五步:运行测试 - 验证通过
```bash
$ ./gradlew test
@@ -189,9 +189,9 @@ RegistrationValidatorTest > multiple errors returns all errors PASSED
PASSED (5 tests, 5 passed, 0 failed)
```
All tests passing!
所有测试通过!
## Step 6: Check Coverage
## 第六步:检查覆盖率
```bash
$ ./gradlew koverHtmlReport
@@ -199,9 +199,9 @@ $ ./gradlew koverHtmlReport
Coverage: 100.0% of statements
```
Coverage: 100%
覆盖率:100%
## TDD Complete!
## TDD 完成!
````
## 测试模式