在Kotlin(Corda)中运行合同单元测试时发生IllegalArgumentException

时间:2019-06-04 12:13:50

标签: unit-testing kotlin corda

当我尝试运行Junit测试(在Kotlin中编写)时,出现以下异常:

java.lang.IllegalArgumentException: Attempted to find dependent attachment for class javax/xml/bind/DatatypeConverter, but could not find a suitable candidate.

我尝试在以下代码中注释/分解某些行,似乎在我调用command()时发生了异常

类IRIssueTests {

class DummyCommand : TypeOnlyCommandData()

private val ledgerServices = MockServices(listOf("com.my.package.name"))

private val ALICE = TestIdentity(CordaX500Name(organisation = "Alice", locality = "TestLand", country = "US"))

@Test
fun mustIncludeIssueCommand() {
    val ir = IRState(
        UniqueIdentifier(),
        mutableListOf(ALICE.party)
    )

    ledgerServices.ledger {
        transaction {
            output(IRContract.ID, ir)
            command(listOf(ALICE.publicKey), DummyCommand())
            fails()
        }
        transaction {
            output(IRContract.ID, ir)
            command(listOf(ALICE.publicKey), IRContract.Commands.Issue())
            verifies()
        }
    }
}

}

我想了解为什么会收到此异常以及如何解决该异常以使我的测试通过

1 个答案:

答案 0 :(得分:0)

Kotlin测试必须与JDK8一起运行。 在运行测试之前,请在项目中更改JDK8的配置。 这样可以避免这种异常情况