DEV Community

Rudy Chung
Rudy Chung

Posted on

OSD600 Lab 8

What I did this week

This week, I added a testing module to my SSG. Since my SSG was created using C++, I used Catch2 as my testing framework. I chose Catch2 as my testing framework since it seemed to be the most popular among C++ developers, and it was all contained within a single header file.

Setting up Catch2

The setup for Catch2 was very simple. I had to include the header to run testing, and using my own command-line argument parsing, I ran the tests from the main function. Then, by calling Catch::Session().run() in the main function, it executed my tests, which I created in a testing file that contained all my test cases. This testing file also included the Catch2 header as well.
Using the macros defined by Catch2 (TEST_CASE, SECTION, and REQUIRE), I was able to specify names for test cases and their sections and define what was expected from each test. Overall, it functioned like Jest, and I'm assuming most other testing frameworks for other languages.

Testing my patience

Since I offloaded my markdown parsing to maddy, I did not test for it because it was not my own code. As a result, it was difficult to find parts that I could test. I mostly created my test cases for end to end testing. Since the number of things to test for is always numerous, I ended up finding a few things I could test for. But, I definitely am not satisfied with the number of tests I currently have and will be adding more in the future.

Caught in the bug net

In one of my tests, I parsed both a .md and .txt file into an .html file and compared them to what I expected the parsed .html to look like. While parsing my .md file, I noticed that it did not product the same .html file as the one produced by parsing the .txt file even though both files' contents were identical. This uncovered something about maddy that I was not aware was happening. It would append a space to each paragraph before the paragraph closing tag. I made a small change to one of maddy's headers that seemed to fix the issue.

What I learned

I learned how testing can be done in C++. Using Catch2, it was very simple to create and run tests. Previously I had only done testing in JavaScript using Jest. In future projects, I will be sure to add testing as it is a good way to maintain all the required functionality and ensure it all functions as intended.

Top comments (1)

Collapse
 
sfrunza13 profile image
sfrunza13 • Edited

So cool! Glad I could catch2 this post!