java - Jacoco coverage and Kotlin default parameters -
i having following constructor:
open class ipfs @jvmoverloads constructor(protected val base_url: string = "http://127.0.0.1:5001/api/v0/", protected val okhttpclient: okhttpclient = okhttpclient.builder().build(), protected val moshi: moshi = moshi.builder().build()) {
now when measuring coverage misses when defaults used. way out can imagine write tests in java use other constructors - stay in pure kotlin - there way this?
update: using constructors ipfs() in tests - think on generated java bytecode converted constructor 3 parameters - , thing jacoco sees
since you're using @jvmoverloads
annotation, compiler generate 3 overloaded constructors. annotation used able omit parameters in plain java.
@target([annotationtarget.function, annotationtarget.constructor]) annotation class jvmoverloads
instructs kotlin compiler generate overloads function substitute default parameter values.
if method has n parameters , m of have default values, m overloads generated: first 1 takes n-1 parameters (all last 1 takes default value), second takes n-2 parameters, , on.
when calling constructor number of parameters in kotlin, default 3-parameter constructor invoked - default values used parameters omitted.
makes sense jacoco not mark overloads covered: they're not.
like @voddan said, these overloads generated, , guaranteed correct. doesn't make sense test these separate.
if want full coverage however, remove @jvmoverloads
annotation. should prevent additional overloads being generated.
if can't remove annotation because calling overloaded constructor java, having java test suite covers these makes sense after all: it's real world scenario want covered.
Comments
Post a Comment