36
恐怖の Fragile Tests問題 @goyoki 2012/4/6 TDDカンファレンス

恐怖のFragile Tests問題

  • Upload
    h-iseri

  • View
    2.662

  • Download
    0

Embed Size (px)

DESCRIPTION

TDDカンファレンス 2012/4/6

Citation preview

  • 1. Fragile Tests@goyoki2012/4/6 TDD

2. Fragile Tests 3. t - w ad a TDD Boot Camp 4. TDD 5. TEST(testHoge, InspectionFugaPiyo){ MotorStatus motorStatus(0, 0); MaintenanceData mtData; MaintenanceType mtType(createRegionID(EU)); setInitialData(mtData, mtType);InspectionFuga inspector;inspector.set(createMaintenanceInfo(mtData, mtType), motorStatus);}TEST(testHoge, InspectionFugaFuga){ MotorStatus motorStatus(-1, 2); MaintenanceData mtData; MaintenanceType mtType(createRegionID(ASIA)); setInitialData(mtData, mtType);InspectionFuga inspector;inspector.set(createMaintenanceInfo(mtData, mtType), motorStatus);} 6. TEST(testHoge, InspectionFugaHoge){ MotorStatus motorStatus(133, 232); MaintenanceData mtData; MaintenanceType mtType(createRegionID(JAPAN)); setInitialData(mtData, mtType);InspectionFuga inspector;inspector.set(createMaintenanceInfo(mtData, mtType), motorStatus);} 7. TEST(testHoge, InspectionFugaHoge){ MotorStatus motorStatus(133, 232); MaintenanceData mtData; MaintenanceType mtType(createRegionID(JAPAN)); setInitialData(mtData, mtType);InspectionFuga inspector;inspector.set(createMaintenanceInfo(mtData, mtType), motorStatus);} 8. Fragile Tests 9. SetUpTearDown 10. 11. 12. Fragile Tests 13. 14. Red Green Refactor 15. orF r a g i l e T e s t s 16. Fragile Tests 17. 18. TEST(FooTest, Bar) { MotorStatus motorStatus(0, 0); MaintenanceData mtData; MaintenanceType mtType(createRegionID(EU)); setIniDalData(mtData, mtType); InspecDonFuga inspector; inspector.set(MaintenanceInfo(mtData, mtType), motorStatus); } 19. TEST(FooTest, Bar) { MotorStatus motorStatus(0, 0); MaintenanceData mtData; MaintenanceType mtType(createRegionID(EU)); setIniDalData(mtData, mtType); InspecDonFuga inspector; inspector.set(MaintenanceInfo(mtData, mtType), motorStatus); :} 20. TEST(FooTest, Bar) { InspecDonFuga inspector = CreateInspecDonFuga(0, EU); inspector.set(MaintenanceInfo(mtData, mtType), motorStatus); } 21. TEST_F(BuyerTest, addSameStatus) { Buyer buyer; Customer customer1("Taro", "Yamada", 15, 2, "HOGE|FUGA"); customer1.addCategory(STATE_ACTIVE); Customer customer2("Taro", "Yamada", 15, 2, "HOGE|FUGA|HOGEHOGE"); customer2.addCategory(STATE_ACTIVE); . buyer.add(customer1); buyer.add(customer2); . EXPECT_EQ(0, buyer.getSecDon()); } 22. TEST_F(BuyerTest, addSameStatus) { Buyer buyer; Customer customer1("Taro", "Yamada", 15, 2, "HOGE|FUGA"); customer1.addCategory(STATE_ACTIVE); Customer customer2("Taro", "Yamada", 15, 2, "HOGE|FUGA|HOGEHOGE"); customer2.addCategory(STATE_ACTIVE); . buyer.add(customer1); buyer.add(customer2); . EXPECT_EQ(0, buyer.getSecDon()); } 23. TEST_F(BuyerTest, addSameStatus) { Buyer buyer; Customer customer1 = createCustomer("HOGE|FUGA"); Customer customer2 = createCustomer("HOGE|FUGA|HOGEHOGE"); buyer.add(customer1); buyer.add(customer2); EXPECT_EQ(0, buyer.getSecDon()); } Customer createCustomer(string status) { Customer customer("Taro", "Yamada", 15, 2, status); customer.addCategory(STATE_ACTIVE); return customer; } Parameterized CreaDon Method 24. TEST_P(HogeTest, InvalidValueMinus) { Hoge hoge(-1); EXPECT_EQ(0, hoge.size()); } TEST_P(HogeTest, InvalidValueZero) { Hoge hoge(0); EXPECT_EQ(0, hoge.size()); } TEST_P(HogeTest, InvalidValueTooBig) { Hoge hoge(124566); EXPECT_EQ(0, hoge.size()); } 25. TEST_P(HogeTest, InvalidValueMinus) { Hoge hoge(-1); EXPECT_EQ(0, hoge.size()); } TEST_P(HogeTest, InvalidValueZero) { Hoge hoge(0); EXPECT_EQ(0, hoge.size()); } TEST_P(HogeTest, InvalidValueTooBig) { Hoge hoge(124566); EXPECT_EQ(0, hoge.size()); } 26. class HogeTest : public tesDng::TestWithParam {}; INSTANTIATE_TEST_CASE_P(InvalidValueInstance, HogeTest, tesDng::Values(-1, 0, 10000)); TEST_P(HogeTest, hogehoge) { Hoge hoge(GetParam()); EXPECT_EQ(0, hoge.size()); } Parameterized Test 27. Fragile Tests 28. RED REDGREENRefactorGreenREFACT GREENOR 29. TDD 30. TDD RED REDGREENRefactorGreenREFACT GREENOR Fragile Tests 31. TDD F r a g i l e T e s t s 32. TDD TDD 33. Fragile Tests 34. RED REDGREEN REFACTOR[TEST]REFACTOR TEST GREENGreen PRODUCT (Refactor[PRODUCT]) 35. 36.