Testing an adapter class within a method

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
kashbridge
Forum Newbie
Posts: 2
Joined: Sun Oct 05, 2008 5:17 am

Testing an adapter class within a method

Post by kashbridge »

I have a class ('Authenticate') with a method Authenticate->login() that itself calls the method of an Adapter class 'AuthenticateAdapter->authenticate(username, password)' to check the username/password combo in a data source. I want to test Authenticate->login. How do I set up the Adapter class call within login()? Do I use a stub or mock object - not really sure I understand either...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Testing an adapter class within a method

Post by josh »

Stub out the adapter, and inject that into your login service.

On the first test the adapter would return true, on the next test it would return false. You would test that the login service is reading that return value back in and acting on it appropriately.

Mock objects differ from stubs in that they verify outbound calls that have no side effects that you can sense.

If you can test the state of the system under test, that is best. A mock object should be used when testing the state of the SUT is awkward. Mock objects can result in over specified software, and high test maintenance cost, two major project "smells".
Post Reply