On 2/1/2016 2:44 PM, Ian Collins wrote:
> Jerry Stuckle wrote:
>> On 1/31/2016 11:48 PM, Ian Collins wrote:
>>> Jerry Stuckle wrote:
>>>> On 1/31/2016 11:11 PM, Ian Collins wrote:
>>>>>
>>>>> Don't forget a mock is often a simple (even machine generated)
>>>>> piece of
>>>>> code with behavior driven by the tests.
>>>>>
>>>>
>>>> If the class completely follows the specifications, then it is not a
>>>> mock class. If it does not completely follow the specifications, you
>>>> cannot thoroughly test dependent classes.
>>>
>>> You can (and thousands of us do) because it *pretends* to implement the
>>> specification. I suggest you do some research on mock objects and how
>>> they are used.
>>>
>>
>> I don't need to do any research on it. I've seen it tried. All it has
>> done is waste time and unnecessarily create bugs because the mock
>> classes cannot, by definition, completely follow the specification.
>
> So you've tried it, done it wrong and given up. Too bad.
>
Nope, I've seen it done before, by more than one group. I've even been
called in a couple of times to manage a project that was mismanaged that
way. Projects that were late and over budget.
>>>> But if the class has to process a file, then you cannot test it
>>>> properly
>>>> unless you process that file.
>>>
>>> Quite - because you aren't testing it! You are testing the code that
>>> process the resulting object.
>>>
>>
>> And you can't test the resulting object because a mock class never can
>> duplicate the behavior of the real class. It can only do some of it.
>> And that means potential problems are missed.
>
> I can't? Bugger, what have I been doing all these years? of course I can.
>
And you've been wasting time and money doing it. Or writing crap code.
I'm not sure which. Maybe both.
>>>> Returning predefined objects or sequence
>>>> of objects does not properly process the input file - and return the
>>>> appropriate information. So all you're doing is testing a subset of
>>>> the
>>>> possible results. Such a process is always prone to errors.
>>>
>>> You've lost the plot, *we are not testing the file processing*. We are
>>> testing the processing of the result of the file processing.
>>>
>>
>> And you can't be sure the output you get from the mock class is the same
>> as what real files will provide in all cases. Only in some cases. And
>> since other cases can't be tested, you leave the possibility of bugs
>> (unnecessarily).
>
> Can't I? The transformation will be well defined and will be testing in
> the real classes tests. Ever heard of a contract?
>
Yes, I've heard of contracts. I've also seen people try your way and
fail miserably. And they thought they were doing it "right" also, until
they saw otherwise.
>> Let's go back to your memory problem. What if processing the input file
>> causes an out of memory condition? Does your mock class emulate that?
>
> Yes, I would simply write something like:
>
> test::FOO_decode::willThrow( std::bad_alloc );
>
> before calling the code that will call the decoder.
>
But that doesn't emulate the out of memory condition. It just throws an
exception. Many other things can go wrong when you truly are out of
memory - things you aren't testing for.
For instance - what happens if the class you're testing allocates memory
while processing the out of memory condition? Since you aren't really
out of memory, that allocation will succeed - where in real life it will
fail. You have just introduced a bug.
>> Or what if data is missing, out of order, or not what was expected? Or
>> the file is truncated? Or any of a number of things a proper test suite
>> would check?
>
> It will - in the tests for the real object.
>
Which means you will have multiple classes to test to see which one is
failing. A waste of tester and developer time.
>>>> Proper testing would include a real class with real input, both good
>>>> and
>>>> bad, and the appropriate processing for all of it.
>>>
>>> Indeed it does, but not unit testing something that has no interest in
>>> how those files are processed.
>>>
>>> I've said it before but it bears repeating: layered testing.
>>>
>>
>> Yes, you have. Now if you'd only learn how to do it correctly.
>
> I'm lucky in that I already do. You don't appear to have got beyond
> understanding what it is.
>
You seem to be quite willing to spend your employer's or client's money
unnecessarily. My job has been to ensure the projects come in on time,
within budget and as free of bugs as possible.
It looks like we have two different goals.