Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Usually when writing unit tests I create a helper class with extension methods. I use these methods exclusively for generating generic data for things that I am too lazy to type out. I usually name these classes something relevant to the class under test - for example, I'll follow a pattern like TestHelper.cs.

I've read that helper classes don't promote good design; however I know SOLID principles pretty well and I don't see how using "helpers" in the way described is violating any principles.

I think the issue I'm having is with the name of my "TestHelper" ... Should I simply come up with a new naming scheme or am I really violating a SOLID Principle by utilizing these helpers?

share|improve this question

closed as not constructive by Mark Trapp Oct 6 '11 at 1:17

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
How is this related to SOLID? To me this question is simply about naming conventions. –  Oded Sep 12 '11 at 20:56
add comment

3 Answers

up vote 4 down vote accepted

This is not anti-SOLID at all, but you may want to consider the Object Mother pattern, which solves exactly the same problem in a similar way and has the added bonus of giving you a funky suffix to use in your class names.

Plus, like all patterns, because they do have a name, any newcomer to the team can simply google the term Object Mother and find a wealth of information, explaining what it is you've done.

share|improve this answer
add comment

I don't see how this violates SOLID or relates to SOLID at all.

In terms of class naming, if the purpose it to generate test data, you can use a naming convention like <test name>DataGenerator and a GetTestData extension method to make it as clear as possible.

share|improve this answer
    
I came across this article a while back and my 'Helper' naming has been bugging me ever since. blogs.msdn.com/b/nickmalik/archive/2005/09/06/461404.aspx –  Robotsushi Sep 12 '11 at 21:04
    
@Robotsushi - looks like a rant about all purpose swiss army knife helper classes. Something that is single purpose as you describe is not a problem. –  Oded Sep 12 '11 at 21:06
add comment

Here some other suggestions, you can use:

  • Mocks
  • [AssemblySetUp] *
  • [FixtureSetUp] *

*(from NUnit, or similar in other framework)

share|improve this answer
    
i seperate the data generators from the test classes or else i would markup the data generation method with : [TestInitialize] –  Robotsushi Sep 12 '11 at 21:04
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.