dimanche 1 mars 2015

C# Unit Tests - Is it ok to extract repeating assertions to a private method

I have been writing tests for a class, all of which look something like this:



expectedResult = ....;
exception = new ....;
mock.Setup(sameexpression).Throws(exception);
result = sameObject.SameMethodToTest();
Assert.AreEqual(expectedResult, result);


I was wondering if it would be considered bad style to extract this code (including the common assertions) into a shared private method, that would receive the expectedResult and the exception as parameters, and thus would reduce code duplication and maintenance.


Aucun commentaire:

Enregistrer un commentaire