kotlin - 将库测试中的测试接口导入应用程序的测试
问题描述
我做了一个图书馆。有序集合。我在应用程序中导入和使用。库中有一个junit5测试接口。我想在应用程序中使用测试接口。
例如,在图书馆你有
interface BinaryTree<K:Comparable<K>,V> : Collection<Pair<K,V> {...}
在你拥有的这个库的测试中
interface TreeTests<K : Comparable<K>, V> {
val tree: BinaryTree<K, V>
@Test
fun sorted() {
val list = tree.toList().sortedBy { it.first }
assertIterableEquals(list, tree)
}
}
我在 BinaryTree 的应用程序中做了一个实现,但它是由 sqlite 支持的。我想在应用程序的实现上使用库中的测试接口。像这样
class TreeDB:BinaryTree<Int,String>(){...}
在应用程序的测试中
class TreeDBTests:TreeTests<Int,String> {
override val tree = TreeDB()
}
然后为 BinaryTree 的可能实现编写的所有测试都在 TreeDB 类上运行。
但是,在库的测试中编写的代码不会导出到库的使用者。无论如何要使这项工作?
解决方案
我建议将测试工具视为任何其他有目的的库。如果在您的情况下似乎还需要这些测试工具来测试原始库,则您必须将接口和实现与原始库分开,例如
bintree-interface <– bintree-testutils (TreeTests etc.)
^– bintree-implementation
现在bintree-implementation
can useTreeTests
的测试和你的TreeDB
can 测试也是如此。
推荐阅读
- rx-java - 为什么在 RxJava 中使用 onBackpressureDrop () 会发生这种情况
- java - Selenium WebDriver / Java - 模拟人类光标移动
- java - Apache Ignite 2.x - 我可以利用堆外存储并且仍然有基于时间的驱逐(来自堆上存储和堆外存储)吗?
- dependencies - Android Studio 中的远程二进制文件是什么?幕后究竟做了什么?
- c# - ActionResult 返回时缺少 Null 属性
- python - Python tz 感知 str 到 datetime 对象以进行重采样计算
- sql - 仅针对特定值忽略 WHERE 子句
- ios - 如何在多个 iOS 模拟器上同时运行 Flutter 应用?
- angular - 将单击事件从一个子组件传递到另一个子组件
- ios - 如何在 SwiftUI 中应用大于底层视图的叠加层