Interesting.
I haven't done BDD myself, so I may be missing something obvious.
Could you explain the benefit of this over
int CalculateAdd(int x, int y) {
Calc calc;
calc.setX(x);
calc.setY(y);
return calc.add();
}
TEST(CalcTest, AddWorks) {
EXPECT_EQ(5, CalculateAdd(2, 3));
}
? Thanks,
--
Zhanyong
Rule 1: Name tests as propositions, not as functions/methods (and not
after functions/methods).
Testing strcat? here are some good names:
TEST(StrcatTests, TwoEmptyStringsShouldResultInAnEmptyString)
TEST(StrcatTests, OneEmptyOneNonEmptyShouldResultInNonemptyString)
TEST(StrcatTests, TwoNonEmptyStringsResultInCombinedString)
Rule 2: if you have to start names with 'test', start instead with 'testThat'
because it encourages propositional names.
TEST(StrcatTests, testThatTwoNonEmptyStringsResultInCombinedString)
Rule #3: if 'should' helps give you more intentional names use it,
otherwise drop the noise and use a more direct name.
TEST(StrcatTests, strcatNonEmptyStringsShouldResultInCombinedString)
Rule #4: watch out for truisms in test names, e.g., using "correct"
or "correctly" in a test name
DON'T DO: Test(StrcatTest, strcatTwoNonEmptyStringsCorrectly)
Rule #5: also treat the use of "can" in a test name with a little suspicion
(but not as much as "correct")
NOT GOOD: TEST(StrcatTests, strcatCanHandleTwoEmptyStrings)
2010/10/22 Zhanyong Wan (λx.x x) <w...@google.com>:
--
--
C. Keith Ray
Web: http://industriallogic.com
Twitter: @CKeithRay, @IndustrialLogic
Amplify Your Agility
Coaching | Training | Assessment | eLearning