首页 > 解决方案 > 无法使用 gradle integrationTest 从 CLI 运行基于驱动程序的测试

问题描述

我在我的 CorDapp 项目的 src/integrationTest/kotlin/com.example.IntegationTest 目录下定义了基于驱动程序的测试:

class IntegrationTest {
private val nodeAName = CordaX500Name("NodeA", "", "GB")
private val nodeBName = CordaX500Name("NodeB", "", "US")

@Test
fun `run driver test`() {
    driver(DriverParameters(isDebug = true, startNodesInProcess = true)) {
        // This starts three nodes simultaneously with startNode, which returns a future that completes when the node
        // has completed startup. Then these are all resolved with getOrThrow which returns the NodeHandle list.
        val (nodeAHandle, nodeBHandle) = listOf(
                startNode(providedName = nodeAName),
                startNode(providedName = nodeBName)
        ).map { it.getOrThrow() }

        // This test will call via the RPC proxy to find a party of another node to verify that the nodes have
        // started and can communicate. This is a very basic test, in practice tests would be starting flows,
        // and verifying the states in the vault and other important metrics to ensure that your CorDapp is working
        // as intended.
        Assert.assertEquals(nodeAHandle.rpc.wellKnownPartyFromX500Name(nodeBName)!!.name, nodeBName)
        Assert.assertEquals(nodeBHandle.rpc.wellKnownPartyFromX500Name(nodeAName)!!.name, nodeAName)
    }
}
}

如果我们尝试使用gradle integrationTest命令行执行测试,我们如何确保 integrationTest 成功执行?

如果使用 Inteliij IDE 进行尝试,Junit 测试将按预期工作,并带有适当的测试报告/日志。

标签: corda

解决方案


为确保集成测试实际运行,您需要使用以下clean参数:

./gradlew clean integrationTest

此命令的输出并不总是清楚地表明已经运行了哪些测试。--info您可以使用以下标志使其显示更多信息:

./gradlew clean integrationTest --info

推荐阅读