3 ms·
>> How many different possible representations of a 'thing' do you have? A json object? Why would you design a function in such a way that one of the arguments
by jondubois 6y ago
>> How many different possible representations of a 'thing' do you have? A json object?
Why would you design a function in such a way that one of the arguments can represent so many different things? The problem here has nothing to do with testing. The problem is that the function itself is poorly designed.
If anything, the difficulty of writing a test for such a function would in itself be an indication that the function needs a refactoring.
- stickfigure 6y agoIt's not the function parameter that has multiple representations, it's your app. The function takes one representation - let's say a numeric id. That doesn't help the client of your function, who could pass in a database id, a database record object, a json object, some sort of natural key, etc... all of which plausibly will match an untyped parameter named "thing". And your function may change its contract someday.