vendredi 5 juin 2015

Unit Tests - where to place initialization code?

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.

  1. Initialize them inside test itself, but that results in tests getting huge
  2. 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.
  3. 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