jeudi 9 mars 2017

Should I factor out duplication between implementation code, solely for reuse in unit tests?

I sometimes find the same block of code or same constant value duplicated between unit tests and implementation code.

In order to reuse the constants in the unit tests, I would need to make the constants something other than private.

In order to reuse the block of code, I would need to extract the block out to some place accessible by the unit tests as well.

I feel uncomfortable doing this because I am reducing encapsulation and/or removing code blocks from their context just for my unit tests.

Should I treat unit test code the same as implementation code and try to apply the DRY principle between them, or is duplication between the two desirable?

Aucun commentaire:

Enregistrer un commentaire