10

I am beginner in developing test cases, and want to follow good patterns for developing test cases rather than following some person or company's specific ideas. Some people don't make test cases and just develop the way their senior have done in their projects. I am facing lot problems like object dependencies (when want to test method which persist A object i have to first persist B object since A is child of B).

Please suggest some good books or sites preferably for learning design pattern for unit test cases. Or reference to some good source code or some discussion for Dos and Donts will do wonder. So that i can avoid doing mistakes be learning from experience of others.

Maddy.Shik
  • 373
  • 1
  • 3
  • 10
  • What is it you're specifically trying to find out? –  Dec 30 '10 at 11:41
  • @Mark: He is looking for references regarding unit tests design patterns. –  Dec 30 '10 at 12:10
  • @Pierre yes, that's what the question says. It's an incredibly broad subject. I'm asking what is it that Maddy.Shik would like to find out about unit test design patterns. –  Dec 30 '10 at 12:14
  • 1
    @Mark: I don't know any of them and I'm very interested in what others will say about them in order to improve my technique in that particular field. Now I agree the question lacks of precision. Maybe we should suggest Maddy to precise his/her question? –  Dec 30 '10 at 12:16
  • 2
    @Pierre that's why I asked the question in my first comment. –  Dec 30 '10 at 12:17
  • 1
    Sometimes it just isn't practical to offer more precision or maybe the OP doesn't know enough to offer more precision. Maybe they are looking for design patterns to better understand how unit testing works because other examples aren't grokking for the OP. I certainly hope no one has voted to close this question as it could prove to be very useful. – Philip Regan Dec 30 '10 at 14:09
  • @Phillip: One person has - as 'not a question.' I too hope it does not close. – Michael K Dec 30 '10 at 14:53
  • 1
    @Michael: That close vote seems to be a little unfair here (please note I'm not blaming you here, I'm just "harumphing"). It is a question despite the fact it literally doesn't have a question mark at the end of it. I, personally, have searched for unit testing examples, and they are surprisingly hard to find if you don't know enough about them. If a question like this can't be asked here, then where else are we supposed to go? Harumph! – Philip Regan Dec 30 '10 at 15:00
  • @Phillip: I completely agree. – Michael K Dec 30 '10 at 15:03
  • 1
    I am beginner in developing test cases. Want to follow some good pattern for developing test cases rather than following some person or company's specific ideas. Some people don't take test cases and just develop the way their senior have done in their projects. I am facing lot problems like object dependencies(when want to test method which persist A object i have to first persist B object since A is child of B) – Maddy.Shik Dec 30 '10 at 15:46
  • 2
    @Maddy - you should add your comments to your question. Your question is a little vague and adding more detail to your question will help. – Walter Dec 30 '10 at 16:11
  • @Philip: Yahoo! Answers? It had precious little to do with the fact that it doesn't have a question mark and everything to do with the fact that the question was overly broad and could be reasonably answered in its previous form. –  Dec 30 '10 at 16:34
  • 1
    @Mark: "Yahoo..." Okay, that's just sarcasm. I still stand by my comment that sometimes it's just not feasible to give more information. I'm not sure that the OP's latest comments really help focus things despite best efforts; even after the comments, this is still a broad, yet potentially very useful, question. One could argue that all overly broad questions are potentially useful (and inversely use*less*), but sometimes I think people are a bit too quick to hit the `close` button around here before letting the question have time to mature with some answers to see which direction it will go. – Philip Regan Dec 30 '10 at 16:48
  • @Philip if a person can't narrow down the scope of a question, the question doesn't belong here. And we're actually [not quick enough](http://meta.stackexchange.com/questions/73382/please-stop-using-programmers-se-as-your-toilet-bowl/73396#73396) when it comes to closing. –  Dec 30 '10 at 17:09
  • @Mark: So, where, *exactly*, is the OP supposed to ask this type question? Where is this question in violation of the Six Guidelines for Subjective Questions? What's the problem with this question when compared to "What are good resources for Design Patterns", which has more answers, more votes, and yet is arguably more general than this one? Unless you are willing to manage all of the other "overly broad" "What are good resources for `topic`?" questions I see in the Related list to the right, then just leave this one alone. – Philip Regan Dec 30 '10 at 18:30
  • @Philip: the vote to close wasn't for violating the six guidelines, and it's a mistake to think that's the only reason why people ought to close questions. It was voted to close as *not a real question*: as being "ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form." But you're creating a false dilemma. It's not "let me ask ridiculously vague and incomplete questions or this site is useless": the question just needed to be refined with the asker's context, and failing that, it needed to be closed. The question, now edited, is fine. –  Dec 30 '10 at 18:37
  • @Mark: With all due respect, I am not making a false dilemma here, though I do think you are being self-contradictory in your judgment. The design pattern question I mentioned earlier (http://programmers.stackexchange.com/questions/2240/what-are-good-resources-for-design-patterns) has *no* context. None. This question had an answer that was voted up *before* the OP refined it, and even then, it's still broad. Again, without a reasonable alternative location to ask these types of questions, they should be allowed either flourish or simply wither on the vine. – Philip Regan Dec 30 '10 at 18:55
  • And to add more, i have gone through various sites for unit testing, most of them have some their tools for testing issues like mocking objects etc but in parallel with lot of other issues. I have posted some specific questions on stackoverflow itself. Since people have difficulty to understand my queries, i thought its better to ask general questions regarding good practices to follow for unit testing. – Maddy.Shik Dec 30 '10 at 20:22
  • Some of questions i posted are like http://stackoverflow.com/questions/4564597/documentation-or-tutorials-for-hibernatemock http://stackoverflow.com/questions/4562235/testing-with-hibernate-object-dependence-chain-on-persistence http://stackoverflow.com/questions/4499494/jtestcase-for-data-in-xml-files-with-junit http://stackoverflow.com/questions/4477256/junit-best-practice-to-develop-test-case – Maddy.Shik Dec 30 '10 at 20:23
  • For those that care, I have taken the discussion of broad questions over to meta: http://meta.programmers.stackexchange.com/questions/817/should-our-faq-contain-a-list-of-whats-off-topic-and-if-so-what-should-that-list. We will now return you to your regularly scheduled program. – Philip Regan Dec 30 '10 at 21:26

2 Answers2

8

Xunit Test patterns, simply a must have.

Unit testing is hardly news, but simply writing a ton of tests guarantees you no bliss. Gerard Meszaros's xUnit Test Patterns distills and codifies the crucial meta-knowledge to take us to the next level. Why do good tests go bad, and how do you fix them--it's as simple and groundbreaking as that. Smells and antipatterns arise in tests that cripple their maintainability. xUnit Test Patterns exhaustively describes those pathologies and provides the prescription in the catalog format familiar since 1994. But fear not - every motivation and pattern includes at least one source-code example and the explanations are couched in clear, direct language. If you're ready to promote your test code to the same level of care and craftsmanship that you devote to production systems, grab a copy of xUnit Test Patterns and get cracking...

gnat
  • 21,442
  • 29
  • 112
  • 288
KeesDijk
  • 8,918
  • 4
  • 35
  • 41
2

http://en.wikipedia.org/wiki/Test-Driven_Development_by_Example

Kent Beck is the originator of the name "Test Driven Development", which is one part of the eXtreme Programming style of development that Beck and his team developed in the 1990's. His books on the topic was one of the sparks of the agile movement.

The above linked book is his book on Testing, and is a clear and good introduction to how to not only test, but make your development test-centric, and the benefits it creates.

Lennart Regebro
  • 2,265
  • 13
  • 17