Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Improve the Code Coverage3:23 with Andrew Chalkley
In this video we'll get our project to 100% code coverage. We'll also take a look at some more important information in our report.
What does the 1x mean?
1x in the margin with a red line means that function hasn't been invoked. Focus on removing red lines and the quality of your tests.
Now we have looked at our report and identified where we can increase code 0:00 coverage on the multiply function, it's time to write some tests. 0:04 In the test folder open the test_calculator_multiplication.js file. 0:10 In this file, we can see that there are three pending tests. 0:16 Let's import the multiply function. 0:20 The first test is to multiply positive numbers together. 0:39 Let's implement that test. 0:42 Let's test the value of 1 multiplied by 3. 0:48 And 5 multiplied by 100. 0:57 Rerun the coverage command. 1:12 If you have the report page still open, refresh it, or reopen it. 1:16 And you'll notice on line 16 in the margin it says 2x. 1:21 This is because we run this statement twice. 1:25 Once to multiply 1 and 3 together, and again to multiply 5 and 100 together. 1:30 While we have 100% coverage now, we can still test more use cases. 1:37 Let's head back and multiply positive and negative numbers together. 1:42 Next add the test where we multiply negative numbers together. 1:58 Let's rerun the coverage command again. 2:12 Refresh the report and now we see 6x. 2:18 We executed line 16, six times. 2:22 Just like in the other statements, 2:26 add, subtract, and divide. 2:31 At this point you may think you're done. 2:34 But remember, 2:37 100% code coverage doesn't say anything about the quality of your code or tests. 2:38 For example, 2:42 how should the divide function operate if zero is passed in as a second argument? 2:43 Are there any numbers that are too big? 2:49 Who knows. 2:51 There's no test cases for those instances. 2:52 You may have also noticed the 1x next to function declarations. 2:55 The reason for this is beyond the scope of this workshop. 2:59 However, if you're interested I've included a technical description of 3:02 the reason in the teacher's notes. 3:05 All you should be really concerned with, is the lines highlighted in red. 3:07 And writing quality tests for those lines. 3:11 I hope you enjoyed this workshop on code coverage. 3:15 I hope you'll include it in the next project that you work on. 3:17 Until next time, keep on coding. 3:21
You need to sign up for Treehouse in order to download course files.Sign up