OSD600 Lab 8 & 9
Lab 8 involved writing tests for our link checker programs! Unlike other labs, this ran for two weeks and consisted of two parts! For the first part, we had to write some tests for our program, and for the second part, we needed to write some tests for another person's program. The testing framework I chose was jest. The two main reasons I chose this was because it's the most popular testing framework for Javascript, and I already had some experience working with it during release 0.3. Another tool I used was the npm module nock. This was so I can make mock requests to websites. Setting up both was pretty simple once I read the documentation. After installing jest make a test file. For example, if you wish to test functions in index.js make a file called index.test.js. To run the test run the command npm run test. Also, make sure in package.json you add "test": "jest" in the "scripts" section. Nock doesn't require much setup besides requiring the API. Writing my tests where pretty straightforward (thanks to my Telescope contribution😊) My tests did not cover any interesting bugs or test cases. When working with Nock I started by reading the documentation, then I tried to write some code. At first, I had a hard time understanding some things so I asked my professor, he provided me with an example, which really helped my understanding of nock. I learned Code Coverage Analysis is built in Jest! Setting it up required some changes to package.json and index.js. First off in package.json I needed to change:
"scripts":{
"test": "jest"
}
to
"scripts":{
"test": "jest --coverage"
}
Then I needed to update my link checker code to make sure it doesn't try to call the processLink() function while --coverage is being passed. This way when I run npm run test, it also prints the code coverage analysis. When I ran the code coverage analysis my test was not covering all possible areas of my code as I have only written a handful of tests, however, they did cover the pathways I wrote!
Comments
Post a Comment