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! 

I didn't have that many problems setting up the GitHub workflow (I followed this tutorial). One thing to note is at first my test was failing because it couldn't find package.json (I put it in the wrong directory). But after I fixed that everything went well. **You can view the YAML file here! My partner's repo testing set up was the same as mine as she was also using jest. Writing tests for a project I didn't create is defiantly more challenging and time-consuming as I needed to take a minute to read and run the code to understand whats going on. How can you test something, if you don't understand how it works? By doing this lab I learned that writing testing can be just as challenging as writing the main code. I can definitely picture myself writing tests in the future. I really enjoy how focused it is. 

Comments

Popular posts from this blog

OSD600 Release 0.4 Part 3

OSD600 Lab 5

Release 0.3 PR2