Say I have a unit under test like this:
internal class MySerializer {
fun serialize(): ByteArray {
val initialBufferSize = 1000
val autoResizeBuffer = true
val value = ThirdPartySerializer(initialBufferSize, autoResizeBuffer)
value.doMoreStuff()
return value.serialize()
}
}
How can I spy on ThirdPartySerializer
, which comes from a 3rd-party library, to make sure that it's called with true
as its second argument?
I normally test the outcome, not how functions are called, but in this case checking the constructor call is ideal: Otherwise, I'd have to write a test to make sure the output can be greater than 1000 bytes, which is problematic because "1000" constant can get out of sync and I wouldn't like to expose it as a public constant on the UUT so it can be used in its tests.