Blog 4


As what we learned in the class, testing is about the process of executing code and comparing the actual results to expected results. If the actual result fit the expected result, then we say the program is successful; however, if the actual result is different from the expected result, there is some problem with your code. There are many kinds of testing, such as unit testing, component testing, integration testing, regression testing, and system testing. In the class 3081, we did a lab which is about testing with cxxTest, which is a kind of unit testing. Unit testing, however, can be defined as an execution of a complete class, routine, or small program that has been written by a single programmer or team of programmers, which is tested in isolation from the more complete system. So as we can see from the definition, cxxTest is a very basic testing skill. Specifically, what we did in the lab is to write the test for a "ReadInput" file, after loading a cxxTest file provided, we try to use it to test ReadInput function, basically, there involved three tests, the first one ensures that the null pointer is returned if no file name is provided, the second one ensures that the null pointer is returned when the name of a non-existent file is passed and the function attempts to access that file, and the third one ensures that when given proper input referring to an existing, readable, filename, the pointer returned is not null. Finally, we modified the "makefile " to include all the test files we just wrote, and run the program to check the testing results. As I mentioned above, cxxTest is a kind of unit testing, which is basic. Thus, this lab is straightforward, but it is definitely a good way to give a general idea of cxxTest. In addition, it helps we to understand the benefit of testing, which we talked about in the lecture that testing improves your confidence that the code is correct, and avoid collateral damaging in fixing bugs. However, to write a good test, there is a long way to go, as we know from Meyer's first principle, when we write a test, we want to make it fail. But as testing can only find errors, it does not demonstrate their absence. Therefore, we should think about as many situations we can that can make the program fail.


I appreciate your explanation for unit testing and why it is important. But I feel that the audience may not actually know what readinput.h is. But you do explain the different tests that you try which does give insight to what the file is.

--Andrew Bork

Hi, I like the way you introduce the concept of unit test and cxxtest. Nice structure flow and it is true that Cxxtest is very handy and easy to use for testing the correctness of our program.It is worth to learn and put into daily practice

Xiaoye Liu

It is easy to write code that covers most cases of a problem, but the trick is coding that all cases are covered. The line about testing to make it fail is very important. The idea of testing is to see if your program works and if you don't cover the weird cases it doesn't fully work.

Alex Busack

Yes, thinking about testing is quite important. And i think your introduction is quite good. It is useful.

Yanjie Zhang

Agreed. I also found that our introduction to cxxTest was a good introduction but there's also a lot more for us to know :)

Cameron Muehlen

I also think testing is one of the most important parts of constructing a program. It makes sure that our program is doing exactly what its supposed to be doing. And I think unit test is extremely important. Everyone could make a mistake even the master of programming. So doing a unit test can make sure that our process is on the right track.

Wenliang Tong

Leave a comment

About this Entry

This page contains a single entry by yexxx108 published on November 7, 2011 2:09 PM.

blog 3 was the previous entry in this blog.

Find recent content on the main index or look in the archives to find all content.