I like to have unit tests which are small and just have the call to the function under test and Asserts.
But I am confused about where to place the initialization code? There are a lot of variables like request/response objects and others which are used by the unit tests. There are a couple of ways to initialize them.
- Initialize them inside test itself, but that results in tests getting huge
- Have a setUp() or initialize() which has the initialization stuff, this results in number of private class variables, but seems better than other 2 since all the initialization code is in one place.
- Have private methods to do that, results in lot of private methods, sometimes 1 test needs 2-3 private methods.
Can any one point to which approach is better? Also any references to some good writeups on this would be appreciated.
Aucun commentaire:
Enregistrer un commentaire