Click here to Skip to main content
12,947,250 members (48,991 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Why test an interface? Why not just test the concrete object(s) of that interface?
Posted 13-May-10 3:20am
Updated 13-May-10 13:04pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

IMO since interfaces do not contain any code, you should not waste time writing tests for them (what is there to test?), if you are talking about interfaces in C#. Test the classes that implement the interface and let it go at that.
Collin Jasnoch 13-May-10 9:35am
That is what I believe also but a google search will result in discussions about using Mock objects.
Doesn't seem like there is a point though, as you said why not test the classes that impliment it.. Then you have it covered.
I just wanted to see if anyone knew something I was missing.
Wes Aday 13-May-10 16:00pm
I do not believe that Mocking an object is the same as testing an interface. Mocking is supplying the unit under test with a fake object so that you can proceed with testing an object without introducing possible bugs from another object. I do not see the two being the same thing at all. And yes it makes my eyes cross when I read it too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Creating a mock object does not necessarily mean that the interface will be tested - a mock object is essentially 'acting as a proxy' for another object that may not be available during testing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,059
CHill60 3,235
Maciej Los 2,538
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 13 May 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100