I'm working on a boilerplate component that's supposed to generate a working sort-of "getting started" project structure. Think of it, in a web app context, of a component that will generate a Controller, a View and the routes configuration so that once you call it, you can immediately go to the browser, type the route and you'll get the output.
In this boilerplate, one of my class has the responsibility of providing the content of every file it generates (the content of the controller file, the content of the routes file, the content of the views fie, etc).
With such a responsibility, wheareas one method should return the content foo
, the test should verify that, in fact, 'foo' is returned.
It ends up looking like this:
// SUT
function getFooFileContent() {
return 'foo';
}
// test
function testGetFooFileContent() {
string expected = 'foo';
string result = sut.getFooFileContent();
assertEquals(expected, result);
}
The people I'm explaining the reason for this test are new to unit testing, so it's normal for them not to grasp at first sight why is this OK, and have doubts whether this test actually has a value to begin with.
Since I'm in charge of introducing unit testing to my team, I want to explain this backed up by resources that explain this "type" of test in particular, so that I have a solid argument rather than asking them to just accept that kind of test.
PS: For the record, when I started with unit testing (self taught, no mentor sadly), I had the same doubt. In my case I just accepted the test and got to understand its value over the years, when I could finally see the fact that tests are supposed to bind functionality to specifications. It's hard to see that when you're starting.
Update 1:
Due to the fact of my question marked as duplicated for the common should I test a getter/setter? I say:
This is not really a getter and the question is not about whether is worth it or not. The class specification is to provide a template text for a boilerplate. The implementation could very well evolve into having it read the text from a non *.php file, and, in that case, a test would have value as it would bind the specification to the functionality.
The question is how to explain the fact that, even with the current implementation (the one that is just returning a string block) the test itself is correct. I'm specifically asking for resources that backup that argument.