Python开发者的终极工具箱:30-seconds-of-python完整指南
2026/6/19 14:20:02
JUnit 官网
Mockito 官网
| @Test | 标记一个函数为测试方法。 |
| @BeforeEach、@AfterEach | 在每个测试方法 前/后 执行,用于 准备/清理 运行环境。 |
| @BeforeAll、@AfterAll | 在所有测试 前/后 执行(必须是静态方法),用于 执行/释放 耗时操作。 |
| @Disabled | 禁用 / 忽略 / 不执行该方法。 |
| @DisplayName | 对 类/方法 取别名。 |
assertEquals(expected, actual) 值 assertSame(expected, actual) 对象 assertNotSame(unexpected, actual) 对象 assertArrayEquals(expectedArray, actualArray) 数组 | 相等 |
assertTrue(condition) assertFalse(condition) | 布尔 |
assertNull(object) assertNotNull(object) | null |
Mockito-Kotlin 最新版本
dependencies { // Required -- JUnit 4 framework testImplementation "junit:junit:$jUnitVersion" // Optional -- Robolectric environment testImplementation "androidx.test:core:$androidXTestVersion" // Optional -- Mockito framework testImplementation "org.mockito:mockito-core:$mockitoVersion" // Optional -- mockito-kotlin testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion" // Optional -- Mockk framework testImplementation "io.mockk:mockk:$mockkVersion" }