Page 1 of 1
Testing an adapter class within a method
Posted: Sun Nov 08, 2009 9:10 am
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...
Re: Testing an adapter class within a method
Posted: Mon Mar 29, 2010 12:30 pm
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".