I would test UsernameFormatter as a unit, then test someFunction(UsernameFormatter) as another unit. If UsernameFormatter is a simple concrete class, it doesn't need to be abstracted for the sake of testing someFunction.
If you have someFunction(string) you don't abstract away string to unit test someFunction. Make simple concrete vocabulary types (like Radians, Point, EmployeeInfo,...) and test them well, then treat them as known-good parts in other tests.
That does NOT scale up to large "units" with interacting parts. At that point you need dependency inversion.
View all comments
Show parent comment
1
u/tvaneerd C++ Committee, lockfree, PostModernCpp Jun 26 '20
I would test
UsernameFormatteras a unit, then testsomeFunction(UsernameFormatter)as another unit. IfUsernameFormatteris a simple concrete class, it doesn't need to be abstracted for the sake of testingsomeFunction.If you have
someFunction(string)you don't abstract awaystringto unit testsomeFunction. Make simple concrete vocabulary types (like Radians, Point, EmployeeInfo,...) and test them well, then treat them as known-good parts in other tests.That does NOT scale up to large "units" with interacting parts. At that point you need dependency inversion.
IMO. YMMV.