In my application I have the option to export/import certain classes. It requires a little more than simple json serialize/deserializing.
Lets say I have a Company class like this
public class Company
string Name
List<Employee> Employees
CEO Ceo
I have an Export() method and I wanted to add a unit test. So I created a test where I arrange a Company, export it and assert some things. Details aren't important.
Now, if I come back in 2 weeks and add a new class Department to my application and a List of Departments to my Company, I need to extend the Export() method as well.
There are 2 problems with this. 1) I need to remember to extend my Export() method. 2) My test won't actually break. I cannot assert for the existence of a property which I don't even know is gonna exist in 2 weeks.
This test is worse than no test. It gives a false sense of security.
I actually wrote a new version of the export method, which should not require constant extension. The key word here is "should". I'm not sure and the test is not helping.
Basically I don't test that my Export() method "works", I test that my Export() method exports the specific Company that I set up in the unit test.
I have to either get around the need to adjust the unit test, every time I change the Company class.
Or, at a minimum, I need a really good reminder to do it. Something like a breaking unit test...
Aucun commentaire:
Enregistrer un commentaire