Unit testing is testing a part of code separately from the main code in order to see if it is properly working. This process allows programmers to test each function on its own to find and correct any errors present thus removing errors before code is complete making it easier to resolve the main code. When one tests by unit testing it lengthens the time to complete each part of the code and one will have to address issues when bringing the code together for whatever reason, but it simpler to see errors within the code as there due to less to filter through. Unit testing does not address every issue because it is like building stairs, you build one step at a time making sure the step is properly made but once finished building you have to add paint or carpet to be complete. In other words, you complete each function of the code (stair) with unit testing but not the code as a whole (staircase) meaning that the code has trouble with using multiple functions interchangeably. These are, in my eyes, a great tradeoff to testing code at the end and having to spend a long time correcting small pieces of code or even rewriting big portions of it to get the main program running properly.
CxxTest is a program used by the 3081W class to do unit testing on code with the functions TS_ASSERT and TS_ASSERT_EQUALS. CxxTest was used as a library to store functions that could be used to run a program with specified input and compare those results with an expected output. The result would print how many tests were run and, if succeeded, would print OK, otherwise it would show the errors in terminal. One of the functions was TS_ASSERT which runs a function or a statement like 2+2==4 to see if true and if so this test is considered to be passed. Another TS_ASSERT_EQUALS which takes in two parameters, a function like 1+1 and an expected result from that function like 2, to see if they match and if so TS_ASSERT_EQUALS passes that test.We tested the program readInput by first creating a readInput test file and its header file, and a makefile in order to test different inputs and compare readInput's results with what was expected. The makefile was created in order to compile the code and access the cxxtest library to get the proper functions available. CxxTest created code in the readInput_test.cpp file in parallel to how many test cases were created.The results worked, shown by it saying OK for completing all the tests in the readInput_tests' file.
Unit testing with cxxTest allowed us to see if our code worked, not just readInput. This was great because it allowed us to find small errors that we could resolve before putting it into the main code eliminating excessive and confusing testing when testing the preliminary main code. This kept us at a smooth speed with our code creation because there weren't multiple errors and we could test with big files and only found small errors present that were easily fixed. There are some code that makes it hard to unit test with cxxTest because it could have special input parameters, no parameters at all, requires global variables, requires use of user created functions, and so on. A way to get around this is to test the functions that are used by desired function that can be tested, place the global variables in the test function area, and create simple versions of the other related functions that can't be tested alone with one possible setting to test the desired function.

Recent Comments