3 ms·
In my experience, it's even a bad idea to share immutable data between tests. At least, certain types. Basically what happens is you write a bunch of tests, an
by Strilanc 7y ago
In my experience, it's even a bad idea to share immutable data between tests. At least, certain types.
Basically what happens is you write a bunch of tests, and they all operate on a Person let's say. So you get into the habit of making a 20 year old Tom with bla bla bla each time. Very repetitive. So you decide to move Tom into a common file that every test can import. Typical DRY stuff.
Then, over time, Tom grows tentacles. Every test that uses Tom needs just one more little detail to be added. Tom needs to have a height for the height test. For the shopping test Tom needs a walking speed and a preference for ladders. These properties keep accumulating, and Tom grows huge. His growing complexities, and his presence in so many tests, make it impossible to remove or edit anything about him. You resort to making Tom variants. In each test you clone Tom then tweak his weight and shoe type or whatever. Of course nobody is making sure that all these properties and property edits are inter-consistent, and you find that because of this even adding properties to Tom has somehow become difficult. Eventually, understanding all facets of Tom becomes a black art. New tests fail sometimes, and no one knows why. You poke and prod Tom for a couple hours, and the problem goes away. Eventually even basic usage of Tom also becomes a black art.
You should have just repeated yourself.