unit testing - Distinguish design and implementation detail when doing TDD -
i have been doing unit tests while. little confused boundary between design , implementation details when doing tdd.
for example, have 2 interfaces, service , adapter, process employee information (add, get, delete ...)
public interface iemployeeservice { employee getemployeebyid(int id) } public interface iemployeeadapter { private iemployeeservice _service employee getemployeebyid(int id) }
by design, service reads data storage such database, file system or web service, adapter uses service information.
this design looks fine until start writing unit test adapters.
the problem need know whether adapter.getemployeebyid(id)
call service.getemployeebyid(id)
(or other methods) determine whether need mock services in test method. makes feel kind of considering implementation detail when writing unit test. there wrong?
unit tests white-box tests, aware of goes on inside system under test. there's nothing wrong using information determine mock. yes, it's implementation detail, , can make test "fragile" in sense of needing change when underlying implementation changes. in case this, want know when call adapter.foo(), calls underlyingservice.foo(), , mocks perfect this.
Comments
Post a Comment