读 JUnit 代码时会遇到哪些类和接口?
查看完整题解
参考回答
直接回答
现代测试常见 org.junit.jupiter.api.Assertions、Test 和 BeforeEach。运行侧可见 Platform 的 Launcher 和 TestEngine。它们分别服务于编写测试和运行测试。
讲清原理
JUnit 4 的断言在 org.junit.Assert。更早的 JUnit 3 使用 junit.framework.TestCase、TestResult 和 TestSuite。JUnit 4 保留了这些旧类用于兼容。
例子与易错点
看见 @Test 导入时先认包名。JUnit 4 的 org.junit.Test 和 Jupiter 的 org.junit.jupiter.api.Test 同名,注解属性与发现它们的引擎却不同。
相关题:第 16 题、第 17 题。
这道题,你掌握得怎么样?
掌握程度由你主动标记,阅读和收藏不会自动改变状态。