From the course: Test-Driven Development in C++

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Add multiple items and calculate the total

Add multiple items and calculate the total - C++ Tutorial

From the course: Test-Driven Development in C++

Add multiple items and calculate the total

- [Instructor] In this test case, I'm going to add prices for multiple items, add multiple items to the checkout, and then verify the correct total is calculated. I'm in the red phase, so first I'm going to add the failing test case. In this test case, I'll add the price for two items and actually add two items and verify that the correct total is calculated. Let me do that now. Test fixture, CheckoutTests, CanGetTotalForMultipleItems. checkOut.addItemPrice("a", 1). checkOut.addItemPrice("b", 2). checkOut.addItem("a"). checkOut.addItem("b"). Int total = checkOut.calculateTotal(). ASSERT_EQ(3,total). As the total should be the sum of one and two for the two items A and B. Let's build this and run it. Excellent. My new test is failing. Great. So I have a failing unit test, so onto the green phase and let's make it pass. Things start to get a little bit more complicated with this test. What I wanna try and do the simplest thing I can to get the test to pass. To do that I'll go ahead and…

Contents