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

Unlock this course with a free trial

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

Throw an exception when adding an item with no price

Throw an exception when adding an item with no price - C++ Tutorial

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

Throw an exception when adding an item with no price

- [Instructor] In this lecture, I'll implement the last test case. Throwing an exception if an item is added to the checkout which does not have a price defined. I'm in the red phase, so I'm going to start by writing a failing unit test. I'll use the Google Test, cert throw macro which is past the function to call, and an expected exception that will be thrown by that function. I'm gonna do that now. Test fixture checkout test item with no price throws exception assert throw checkout.add item A standard invalid argument Okay. Okay. So now that I've got my failing unit test, I'm going to go to the green phase, and I'm gonna make it pass. I'll make this pass by modifying the add item method to check if the passed in item has a price specified. If it doesn't, then I'll throw the exception. So I go to my checkout CPP. And I wanna modify the add item method. So first, I'm going to search my list of prices to see if I have a price for this specified item. Standard mop standard string int…

Contents