tcvan0707

Thanh Van

Posted on November 12, 2021

OSD600 - Lab 8

Introduction

Hello all, this week I have to add a Testing Framework to my program-SSG. By doing this, I will be able to test different pieces of my code. Moreover, I also have a basic concept about how to test a program. My program is still small compare to others project, which is super convenient when we know how to test it, and what to test. Let's get started!

How to Begin with Testing

Firstly, I do a research of some testing frameworks, and I come up with Jest because I found that Jest is able to speed up the overall testing process, plus it is developed by Facebook. In order to install it for my program, I run:

npm install --save-dev jest
Enter fullscreen mode Exit fullscreen mode

After installing, I have created my first test file named generator.test.js, and I gradually add my test in there. The reason why I am doing it because I know my mind is going to blow up if I add everything in a single time, and I will definitely have a bunch of errors by doing that. So, I decide to add one function to test at a time. My program is only contains two files, so that it is pretty straightforward to test it, I also create txt2html.test.js to do some tests. During testing process, I have to change some of my code to make the test pass. And I finally come up with my commit.

Additional Configuration

I have modify my package.json file to include the script running Jest automatically. I do the following:

"scripts: {
   "test": "jest",
    ....
}
Enter fullscreen mode Exit fullscreen mode

I run npm run test, Jest will be run automatically and I receive this for my test process: test pass The further I go with OSD600 course, the more knowledge I can learn. More specifically, this is the first time I have worked with testing framework, which I do not normally do. However, I will definitely use Jest again for my future work since it is so powerful.

💖 💪 🙅 🚩
tcvan0707
Thanh Van

Posted on November 12, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

OSD600 - Lab 8
opensource OSD600 - Lab 8

November 12, 2021