in reply to Re: Universal test flag
in thread Universal test flag
If code needs to know that it is being tested, I suspect something wrong with the interface.
Probably so, and in theory everything sound nice, but in real-world every-day coding, with a team of coders, and with time and budget constraints, this is by far the common case. You need to be able to test things while skipping others that don't concern that particular aspect that you are working on or testing.
Example: you are testing a class that invokes an external service to send an SMS, and the SMS gateway has no test mode, so it costs you money. Your class does a hundred things besides sending the SMS and has a lot of business logic and you only want to skip the SMS sending part to test this logic. Maybe the SMS sending logic was encapsulated in a class (in which case could be mocked) or maybe it's part of the same class on a sub and can't be mocked. Like this one, there are a many day-to-day scenarios where you want to skip over some part of the code just o test the overall logic.
Refactoring to make code perfectly testable is not always an option, in fact, it rarely is, at least in large projects. The code is far from perfect and you have to make the best of it and try to test it as best you can within the time and budget constraints that a particular project allows.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Universal test flag
by chromatic (Archbishop) on Jul 17, 2012 at 17:02 UTC | |
Re^3: Universal test flag
by zwon (Abbot) on Jul 17, 2012 at 18:25 UTC | |
Re^3: Universal test flag
by ait (Hermit) on Jul 18, 2012 at 13:42 UTC | |
by chromatic (Archbishop) on Jul 19, 2012 at 17:44 UTC | |
by ait (Hermit) on Jul 19, 2012 at 18:46 UTC | |
by chromatic (Archbishop) on Jul 19, 2012 at 19:06 UTC | |
by zwon (Abbot) on Jul 18, 2012 at 17:08 UTC | |
by ait (Hermit) on Jul 19, 2012 at 12:07 UTC | |
by zwon (Abbot) on Jul 19, 2012 at 13:29 UTC | |
by ait (Hermit) on Jul 19, 2012 at 19:00 UTC |