What have I to test?

I'm currently working on a software who has to create a PDF document from an ODT template. Of course, I'm doing in python, and I want to test it.

Actually, I already have the methods to create the PDF document.

At the moment, however, the name of the template is hard coded in a class; the name leads to a file on the file system, in a specific directory, which contains the template.

My next story requires that the name of the template to use bs different according to the configuration of an object.

So, the first step could be to askthe name of the template to the object. In a first implementation, the method returns a fixed string; later, I can make it provide different names according to different configurations.

Of course, this part is quite easy to check; also, I don't deal with actual templates, but just with file names.

There is another part, however, which is not so easy: the other object which uses this path to actually build the PDF. In this case, my problem is that I've to get the file name and actually build the object. Or I could use a fake, for this special case, and just check if the path required is passed to me.

This is not so good. I'm checking the implementation. Rather, I want to check the results of this method.

To be able to check the results, I've first to define what are the results I want to check.

I could say that the results are the PDF document (i.e. the file) produced by my method. Even though this can be fine, up to a point, it is not worthy. A generated file can differ from the file used as a compare because of stupid reasons, like the date of creation, or the path of the document which could be embedded in the document itself, or anything else. In short, even though the "content" could be the same, the binary of the two files could be quite different. This is no good, and it should be avoided.

So, I think that in the end I will unit test whatever I can test, mocking and checking that the interactions are actually performed how I expect them to be performed, and then I will make a real test with real openoffice in the acceptance tests.

Comments

Popular posts from this blog

Trenitalia e gli Eurostar

Magicworks and patrons