Unit test on Kotlin Extension Function on Android SDK Classes : <p>Kotlin extension function is great. But how could I perform unit test on them? Especially those that is of Android SDK provided class (e.g. Context, Dialog).</p>

<p>I provide two examples below, and if anyone could share how I could unit test them, or if I need to write them differently if I really want to unit test them.</p>

<pre><code>fun Context.getColorById(colorId: Int): Int {
    if (Build.VERSION.SDK_INT &gt;= 23)
        return ContextCompat.getColor(this, colorId)
    else return resources.getColor(colorId)
}
</code></pre>

<p>and </p>

<pre><code>fun Dialog.setupErrorDialog(body : String, onOkFunc: () -&gt; Unit = {}): Dialog {
    window.requestFeature(Window.FEATURE_NO_TITLE)
    this.setContentView(R.layout.dialog_error_layout)

    (findViewById(R.id.txt_body) as TextView).text = body
    (findViewById(R.id.txt_header) as TextView).text = context.getString(R.string.dialog_title_error)
    (findViewById(R.id.txt_okay)).setOnClickListener{
        onOkFunc()
        dismiss()
    }
    return this
}
</code></pre>

<p>Any suggestion would help. Thanks!</p>
