c# - Do I have to fake a value object in my unit test -


i have written class using tdd containing method (method under test) takes simple value object parameter (range).

code:

the method under test looks this:

public list<string> in(irange range) {      var result = new list<string>();      (int = range.from; <= range.to; i++)      {           //...      }      return result; } 

furthermore have unit test verify method under test:

[testmethod] public void in_simplenumbers_returnsnumbersaslist() {     var range = createrange(1, 2);     var expected = new list<string>() { "1", "2" };     var result = fizzbuzz.in(range);     collectionassert.areequal(expected, result); }  private irange createrange(int from, int to) {     return new fakes.stubirange()      {          fromget = () => { return from; },          toget = () => { return to; }      }; } 

question:

i have read roy osherove's book on unit testing ("the art of unit testing"). in there says

"external dependencies (filesystem, time, memory etc.) should replaced stubs"

what mean external dependency? value object (range) external dependency should faked? should fake dependencies class have?

can give me advice

tl;dr

do simplest thing possible solves problem.


the longer have been using tdd, more appreciate value of being pragmatic. writing super-duper isolated unit tests not value unto itself. tests there write high quality code easy understand , solves right problem.

adding interface range class idea if have need able switch concrete range implementation without having modify code depends on it.

however, if not have need adding interface serves no real purpose, add complexity, takes further goal of writing easy understand code solves problem.

be careful not think might change in future. yagni principle follow. if have been doing tdd won't have problems refactoring code if actual need occurs in future, since have solid tests rely on.

in general terms not consider proper value object dependency. if complex enough feel uncomfortable letting other code use when under test sounds more service.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -