importorg.trustweave.testkit.*importorg.trustweave.did.*importkotlin.test.Testimportkotlin.test.assertNotNullclassDidMethodTest{@TestfuntestCreateDid()=runBlocking{valkms=InMemoryKeyManagementService()valmethod=DidKeyMockMethod(kms)valoptions=didCreationOptions{algorithm=KeyAlgorithm.ED25519}valdidDoc=method.createDid(options)assertNotNull(didDoc)// DidDocument.id is a Did value class; use `.value` for the raw string.assert(didDoc.id.value.startsWith("did:key:"))}}
@TestfuntestErrorHandling()=runBlocking{valkms=InMemoryKeyManagementService()// KMS operations return sealed Result types — pattern-match, do not .fold().valresult=kms.sign(KeyId("nonexistent-key"),"data".toByteArray())assertTrue(resultisSignResult.Failure.KeyNotFound)}
Testing Validation
1
2
3
4
5
6
7
8
@TestfuntestInvalidInput()=runBlocking{valmethod=DidKeyMockMethod(InMemoryKeyManagementService())// resolveDid takes a Did value class and returns DidResolutionResult.valresult=method.resolveDid(Did("did:key:unknown"))assertTrue(resultisDidResolutionResult.Failure.NotFound)}
Best Practices
Resource Cleanup
Always use use {} for cleanup:
1
2
3
4
fixture.use{fixture->// Test code// Automatic cleanup on exit}
// GoodassertNotNull(didDoc,"DID document should not be null")// DidDocument.id is a Did value class — use `.value` for the raw string.assertEquals("did:key:",didDoc.id.value.substring(0,8),"DID should start with did:key:")// Less clearassert(didDoc!=null)assert(didDoc.id.value.startsWith("did:key:"))
Test Coverage
Coverage Goals
Aim for:
Unit Tests – 80%+ coverage
Integration Tests – cover critical paths
End-to-End Tests – cover main workflows
Measuring Coverage
Coverage tooling is not wired into the build today. The root build.gradle.kts
applies neither JaCoCo nor Kover, so ./gradlew tasks will not list a
jacocoTestReport (or koverReport) target — running it fails with
Task 'jacocoTestReport' not found.
To collect coverage locally, apply a plugin in your fork and re-run tests, for
example:
1
2
3
4
// settings.gradle.kts or root build.gradle.ktsplugins{id("org.jetbrains.kotlinx.kover")version"0.7.6"}
1
./gradlew test koverHtmlReport
Wiring coverage into the upstream build is tracked as a separate workstream — open
an issue if you want it adopted project-wide.