Check out a free preview of the full Software Developer Success: Soft Skills & Testing course

The "Specialty Item Tests" Lesson is part of the full, Software Developer Success: Soft Skills & Testing course featured in this preview video. Here's what you'd learn in this lesson:

Francesca continues writing tests to check the quality of the shop's specialty items.

Preview
Close
Get $100 Off
Get $100 Off!

Transcript from the "Specialty Item Tests" Lesson

[00:00:00]
>> Francesca Sadikin: So for my specialty items, I'm going to group them as well, and I'm gonna call them specialty item behavior.
>> Francesca Sadikin: Another callback, inside of this, I'm going to create another one for each particular item. So I'm going to say this is HB. And then now we have a condition here.

[00:00:26]
So age three actually increases in quality the older it gets. So I'll call this, it should increase in quality.
>> Francesca Sadikin: Okay, and this time, I'm going to create my new gilded rose shop with a single item instead of foo. I'm going to use this age three term. I'm going to have a selling of ten and a quality of 20.

[00:00:59]
I'm going to call gilded rose, update quality, and now I expect that the first items quality. Actually let me check the sell in first. Just making sure that the behavior is as expected. So if it's like a regular item, it's going to just be nine, in this case, which is right, and then now I check the quality, increases in quality, so it should be 21, okay.

[00:01:40]
>> Francesca Sadikin: It also says that the quality of an item is never more than 50, so I'm noticing that this isn't tied to any particular item, but it looks like an item that increments will never be more than 50. So I'm gonna add that case. I'll call it, it should never have a quality more than 50.

[00:02:00]
So it should never have a quality more than 50.
>> Francesca Sadikin: So I'm gonna create my new gilded rose, shop with a single item called aged Brie. I have a sell in of ten. This time I have a quality of 50, so I'm gonna grab items from gilded rose, update quality, and now I expect that the items quality is going to be 50.

[00:02:39]
So it's never going to go past that. Okay, so let's see everything's there. Okay, so let's do the next item. We have Sulfuras. So I'm gonna create another describe block here Sulfuras. And this one's going to say, it should never, so far as being a legendary item, never has to be sold or decreases in quality.

[00:03:11]
So I'll just say it should not change quality or selling. Should not change quality or selling.
>> Francesca Sadikin: I'm gonna create my new items. I'm sorry, [LAUGH] I'm going to create my new gilded rose shop, which has a single item. I'm going to take the name that's in the requirements field so first, gonna have a sell in of ten, quality of 20.

[00:03:44]
And then I'm gonna grab items from gilded rose update quality.
>> Francesca Sadikin: And now I expect that the first items sellIn is going to be here, so if it doesn't change, it should be ten. Except when I click save, this is failing, right? We expected ten, but it received nine.

[00:04:12]
So I think there's something wrong with the way we're writing our tests. So when I actually go into the code I can see very quickly that actually the name of the test is Sulfuras, Hand of Ragnaros. That is actually the full name match. So I'm gonna grab that, put this in.

[00:04:34]
Okay, so now, we have the actual test so I'm gonna rename this describe block, whoop.
>> Francesca Sadikin: There we go, okay. So we had checked selling, let's also check the quality now.
>> Francesca Sadikin: To be 20, doesn't change. Perfect, okay, now we have backstage passes, so let us create a new describe block for this.

[00:05:09]
Okay, so backstage passes like aged brie increases in quality as it's sell in value approaches. And then it changes how much it increases by as it gets closer to zero. But let's handle this one first. So I'll say it should increase in quality if it's more than ten days, if there are ten days, okay, so.

[00:05:39]
If it's 11 days or more so that's what I'll call it, it should increase in quality if selling is 11 days or more.
>> Francesca Sadikin: So gonna create my new gilded rose shop with a single item, gonna just paste this string in as the name of the item.
>> Francesca Sadikin: Doesn't know what to do with that code.

[00:06:09]
Selling of 11, quality of 20, right? Cuz we're checking this is the default case and it has to be 11 days or more, so I'm going to grab items from gilded rose update quality. Let's do our usual check at the selling is decrementing as expected. So I expect this to be ten, yeah?

[00:06:41]
And then I'm now going to check quality. I expect that to be 21, except it's failing again. So it's decremented instead. So I'm actually gonna go back to the source code and I saw it when I was looking at the Sulfuras, that this is actually the full name of this item.

[00:07:02]
So I'm just going to copy that, paste it in here, and I'll also change the describe block as well. Okay, so we have that first case. The second one is that the quality increases by two. When there are ten days or less. Actually, before I do that, I actually want to write a test case for this that the quality of an item is never more than 50.

[00:07:29]
So I'm going to actually copy this test cuz it's going to be very, very similar. I'm just going to just say, but never more than 50. And I'm going to add 50 to the quality. I'm going to click Save. I know it's going to fail, but yes, I've received 50, so I'm just gonna add that in, okay?

[00:07:55]
And now we can do the next one.
>> Francesca Sadikin: Quality increases by two when there are ten days or less. Really, it's between ten days and six, right? If I read that requirement. So it should increase quality by two when the selling is between ten days and six.
>> Francesca Sadikin: Inside of this, I'm going to create my new gilded rose shop with a single item.

[00:08:33]
I'm going to just paste this name. I'm going to have a selling of ten this time, quality of 20. Woop, went too fast. Const, items equals gilded rose, update quality, and now I expect that the items quality,
>> Francesca Sadikin: There is going to be, let me look 20, so 22, okay.

[00:09:10]
Same deal here, I'm going to just double check that even when we increment by two, it's never gonna be more than 50, never more than 50. So I'm gonna change this quality to 50. It's going to fail, I'm just gonna let it run, yep. And then received 50.

[00:09:29]
There we go. And then we have a third case. It increments quality by three when there are five days or less, so specifically between five and one days. So it should increase quality by three when the selling is between five days and one. Here's my callback and here's my gilded rose shop.

[00:10:06]
With a single item, I'm gonna grab that string.
>> Francesca Sadikin: This time, I'm going have a selling of five and a quality of 20. I'm going to create my items and here's from update quality. Now I expect that the items quality is going to be, lemme look at it.

[00:10:35]
20 increments by three, 23, okay. As you guys expected, we're gonna check again that it's never gonna be more than 50 in this case as well. There we go, this is going to fail, I'm gonna let it fail. Yeah, received 50. Okay, we're almost done, we have one more.

[00:11:01]
Quality drops to zero when has a selling of zero, sorry, drops to zero when the selling date has passed. So I'll call it, it should drop quality to zero when selling has passed.
>> Francesca Sadikin: So here I'm going to create my new gilded rose shop.
>> Francesca Sadikin: Drops to zero after the concert, okay.

[00:11:32]
With a single item, I'm gonna grab this string. This time, I'm going to have a selling of zero, and then in quality of 20. I'm going to grab items from gilded rose, update quality. And then going to write my assertion now. So here, the first items quality is going to be zero.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now