Unit Testing: Interfaces VS Implementation

Niko Sams niko.sams at gmail.com
Sun Jun 12 10:29:40 UTC 2011


On Sun, Jun 12, 2011 at 00:17, Milian Wolff <mail at milianw.de> wrote:
> Niko Sams, 11.06.2011:
>> On Sat, Jun 11, 2011 at 17:31, Milian Wolff <mail at milianw.de> wrote:
>> > Milian Wolff, 11.06.2011:
>> >> Hey all,
>> >
>> > status update, please read the first mail as it's still valid.
>> >
>> >> * ShellBuddyTest (fails since current implementation lies in KDevelop)
>> >
>> > if someone tells me how, I would like to move the test files to
>> > kdevelop/languages/cpp/test and keep their git history.
>>
>> I think there should be a very basic IBuddyDocumentFinder implementation
>> inside the test. And this test should then only test the code in
>> kdevplatform.
>>
>> The concrete implementation in the cpp plugin should be tested as you
>> suggested in cpp, but there only the cpp implementation has to be tested -
>> not the documentcontroller plus
>> the cpp stuff.
>>
>> As Andreas said alrady, unit tests should test only as small as
>> possible units, while
>> integration tests test everything together. In theory when all units
>> are tested perfectly
>> there is no need for integration tests.
>> However integration tests are often easier to write, esp. for code
>> that is not designed
>> to be unit tested.
>
> Hmm I probably simply don't get it: You rather want to copy the implementation
> code from KDevelop to KDevplatform and then test the interface using that?
No, create a very basic implementation that uses eg. hardcoded values.
Just enough
to test DocumentController.

> Considering that the implementation still has to test this all to make sure it
> all behaves correctly - what do you gain? Why not simply write something like
> ModelTest that you can plug in any kind of implementation and then just test
> it all?
In theory it is easier to work with smaller units, one test tests only
a small part of the code.
It is easier to see which part fails, easier to debug, usually faster
to run the test.
However in practice it is not always the easiest way to go, especially
if the code is not
designed with unit-testability in mind. Mainly for (existing) UI Code
it is often impossible.

Niko




More information about the KDevelop-devel mailing list