I'm writing unit test for something that has a required initializer that takes a Decoder
as parameter, the decoder isn't used in my test and the object is also only a dummy placeholder for something else, however I need to provide some instance that conforms to Decoder
protocol, I checked JSONDecoder
but it doesn't conform to the protocol, then I thought about creating a lightweight class that conforms to Decoder
and basically has empty protocol methods / properties. Now, having to implement functions like:
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey
func singleValueContainer() throws -> SingleValueDecodingContainer
func unkeyedContainer() throws -> UnkeyedDecodingContainer
feels to me like an overkill since I still have to construct objects to return, is there any existing/native class that conforms to Decoder
so I can use as a dummy object for unit test?
Thanks!
Edit:
The reason for using this, is that I have an object (the one with initializer takes a Decoder
, say ObjA), the object itself is a non-nil property of another object (say ObjB) and the unit test is to do with the other object, as a result I need a dummy ObjA which need a decoder to initialize.