In some situations, I have to use a delegate class which just delegates the incoming request to another class.
for example,
public class ServiceDelegate
{
private EmployeeService service;
public List fetchEmployees()
{
service.fetchEmployees();
}
}
Though this class does not do any logic other than calling the service class, still I am thinking , we should verify if the delegation happens properly or not , through unit testing, possibly by one positive test case. Is it the correct approach?
Some of my friends say that unit testing code which is not doing any logic, like delegation, is a waste of time. Please advise.
Appreciate for your answers.
Unit testing is valuable for two reasons: it tells you what code to write, and it makes sure that code doesn’t change accidentally.
@RustyTheBoyRobot makes a good point in his comment. I would expand it: if you feel like you don’t need a unit test for some piece of code, it likely means you don’t need that piece of code.
However, I often write very thin proxies or adapters. Caching proxies especially call for some testing around when delegation occurs. In those kind of cases, unit tests are entirely appropriate.
Shameless plug: here‘s a utility class that makes delegation testing easier.