Blog 4 Testing

| 3 Comments
    So far this semester, my partner and I haven't really wrote any unit tests for our project. Besides writing tests in the lab exercises, I have never used cxxTest. I understand the importance of unit testing, but when we write our code we try to make sure it outputs the same data as the sample output given to us and we don't do this until we finish writing almost all the functions.
    cxxTest is a testing framework for c++. I don't know how if there was some installation behind the scenes before we started using cxxTest, but when we first used it we extracted cxxTest in a specific directory structure within our group repository. After that, cxxTest just worked. It was quite fun writing small tests and seeing it run in lab. It's the only testing framework that I know of for c++ and for our purposes, I believe it's sufficient. I don't write a lot of test cases and I don't know how to write more advanced testing techniques.
    Writing code and testing each function before moving on to the next is helpful and ensures that you can be confident in your code working and this is what unit testing is for. This practice can save a lot of time in the long run. When we were programming for iterations 1 and 2, we didn't run our program until we thought we were finished. Only then, did we compare our program's output to the expected output, but before we could even do that we ran into a lot of errors that we were unsure of. We spent hours trying to figure out what was wrong. Was it our regular expressions? Or was it something we missed in our consumeWhiteSpace function? Maybe we didn't correctly output the data in our printout method? This would not have been so hard to debug if we would have wrote unit tests. It would have helped us to eliminate many factors and pin pointed us to a more exact cause of the error.
    Ideally, writing unit tests through cxxTest is a very good way to program big projects, but my partner and I just don't do it. Perhaps it is just a bad habit of mine not to write small tests to make sure all the underlying methods work before I move on to the next method. Since unit testing is used for testing small parts of the whole program I don't think a lot of time will or should be spent on it. As it focuses on a small portion of the overall code it may still miss some unforeseen errors.

3 Comments

In my opinion, one of the better reasons to use unit tests is that they can be reused if you "refactor" the code.

Even in the relatively small project we are doing in this class, we have refactored twice now, if I remember correctly.

The first time the class refactored, we weren't using unit tests, and we did have to write a new set of tests. The second time, we were using unit tests, and we reused those tests.

I think you and your partner is doing well in CxxTest, the small unit test is not necessary unless larger tests where these small functions are invovled in the computation fails. Testing is just a tool to help us verify the code or find bugs, it is not a necessary procedure. (no one would want to design a full test to see if a + b returns correctly, right?)

I think that the fact that you don't use CxxTest to it's full potential is proof that you don't understand all of the benefits that come with it. Last time that I used CxxTest I cut development time in half. :D

Leave a comment

About this Entry

This page contains a single entry by lorxx033 published on November 10, 2011 1:57 AM.

Blog 3 Subversion and Source Control was the previous entry in this blog.

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