Android. Unit testing for SpannableString

448 Views Asked by At

For testing my business logic I'm using mockk library. But I also have a few helper classes that contain methods that use SpannableString, ForegroundColorSpan etc. I need to write tests for these methods as well. However, I do not quite understand how to write such tests correctly, since before that I wrote tests only for business logic. Can I write for testing a SpannableString test using mockk . Unfortunately, I have not found any good examples to demonstrate how to write such tests. Please help me. Here is example of code for which i need to write tests:

fun formatSum(sum: Double): SpannableString {
    return SpannableString(sum.toString()).apply {
        if (ceil(sum)!= sum) {
            setSpan(
                ForegroundColorSpan(getColor(R.color.red)),
                sum.toString().length - 2,
                sum.toString().length,
                0
            )
        }
    }
}
0

There are 0 best solutions below