For example, I have a piece of code that's generating a SQL*Loader control file from this template (using Python):
template = """
LOAD DATA
INFILE '%(file_path)s'
APPEND
INTO TABLE %(table_name)s
FIELDS TERMINATED BY "%(delimiter)"
OPTIONALLY ENCLOSED BY ""
(\n%(column_specifications)s\n)
"""
There are only two ways that I can think of to unit test this:
- Come up with inputs, figure out what the output should look like, then assert that the output is equal to that.
- Test that certain strings that should be in the file are in the file.
To me, these tests represent two different extremes. The first technique seems very fragile because I have to update the test if I do so much as change the whitespace. The second technique seems almost useless because it doesn't really test that text is going in the right place. Is there any kind of happy medium here that will keep my tests simple?