Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Prag Dave:
We say "put as many tests in the method as makes sense!" I'm not sure I see any benefit to restricting yourself to one test per method, but at the same time I also feel strongly that each test method should address a coherent set of issues. If you're testing a search method, I'd personally test "normal" behaviors in one test method, and then exceptional behaviors in one or more separate methods. It all comes down to optimizing convenience and readability.
Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
And sometimes it's just fine to rely on the equals() method:Originally posted by Ilja Preuss:
Another technique to reduce the number of asserts in a method is to write custom assert methods.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Jeff Langr:
If I were to try and see the side of the "one asert per test camp" (which I think also includes Jim Newkirk), it might be that the goal of pushing in that direction leads to designing methods that are better composed.
Dave Thomas <br />Author of "<a href="http://www.amazon.com/exec/obidos/ASIN/020161622X/ref=ase_electricporkchop/002-7467239-7061602" target="_blank" rel="nofollow">The Pragmatic Programmer: From Journeyman to Master</a>
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
To get around the problem of not knowing what was different for larger objects, we wrote an assertion that uses reflection to compare the fields one by one. That way we can tell at a glance which field is wrong and what the two values are.
Ah. True. Obviously assertEquals() would work better. I did have a point, though, but I can't remember anymore what it was...Originally posted by Jeanne Boyarsky:
Lasse,
Why would you use
assertTrue(expected.equals(actual))
instead of
assertEquals(expected, actual) ?
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jeanne,
Have you made that utility publicly available somewhere?
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |