从库的测试中导入一个测试接口到应用程序的测试中

import a test interface from a library's tests into application's tests

我做了一个图书馆。有序集合。我在应用程序中导入和使用。库中有一个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 class.

上 运行

但是,在库测试中编写的代码不会导出到库的使用者。无论如何使这项工作?

我建议将测试实用程序与任何其他有目的的库一样对待。如果在您的情况下,测试原始库也需要这些测试实用程序,则您必须将接口和实现与原始库分开,例如

bintree-interface <– bintree-testutils (TreeTests etc.)
                ^– bintree-implementation 

现在 bintree-implementation 的测试可以使用 TreeTestsTreeDB 的测试也可以。