What Makes a Good Test?
2014-03-18
Tests provide more than verification. They also serve as documentation.
As a source of documentation, test should not be distracting or hide information.
Bad
TEST(CalculatorTest, ShouldPerformAddition) { Calculator calculator(RoundingStrategy(), "unused", kEnableCosinFeature, 0.01, kCalculusEngine, false); int result = calculator.DoComputation(MakeTestComputation()); EXPECT_EQ(result, 5); }
Good
TEST_(CalculatorTest, ShouldPerformAddition) { const int result = calculator_.DoComputation(MakeAdditionComputation(2, 3)); EXPECT_EQ(result, 5); }