In my application, I have two classes: a logger that actually logs to the database and a dummy logger that does nothing (used when logging is disabled). Here is the entire DummyLog class:
class DummyLog(object):
def insert_master_log(self, spec_name, file_name, data_source,
environment_name):
pass
def update_master_log(self, inserts, updates, failures, total):
pass
On one hand, I should probably let this go and not test it since there's not really any code to test. But then, my "test-infected" instinct tells me that this is an excuse and that the simplicity of the class means I should be more willing to test it. I'm just having trouble thinking of what to test.
Any ideas? Or should I just let this go and not write any tests?
If you don't test, how will you really know it does nothing? :)
Sorry - couldn't resist. Seriously - I would test because some day it might do more?
Of course you can test a class that doesn't do anything. You test that it does, in fact, not do anything.
In practice, that means:
Don't run this test on DummyLog; use it as a generic test and run it on all loggers. When you add another method to the real Log class a year from now and forget to add it to DummyLog, the test will notice. (As long as you do remember to add a general test for the method, of course, but hopefully adding the test should be habitual, even if you forget about related classes.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With