I wrote a small INI file parser as a library which I want to use in a bigger project. Following good practice I decided I should write test cases, too. But I fail to find a good start.
- The library is extremely small (1 source file for the implementation, 1 header)
- The library has few public methods. (
parse(), get_sections(), get_value(section, key))
- Most logic is private to the implementation, therefore not trivially accessible for tests.
- The input for a test would be an INI file and I don't want to write multiple test INI files.
So the first test I'd write is:
- Call the parse method on a provided test input INI file and check that it was successful.
- Hardcoding expected sections and key-value pairs in the test itself and check that all of them are there.
- Also check that no other sections and key-value pairs were extracted.
I am unhappy with that. Maintaining the expected output and the input files is quite a burden. The tests will fail when you update the input but not the expectations which I think is a bad design decision for tests.
There are many guidelines for writing good tests out there, but I always find it hard to apply them. I guess experience is the key. So maybe you can guide me to some good example codes or share your personal experiences? Much appreciated.