Unit testing and CxxTest


There are many different kinds of testing while developing software. Unit testing, perhaps is one of the essential and basic form of testing which is usually performed by individual developers. Unit testing as you can guess from its name, is a test for a certain functionality, a unit. What we want to test is whether code(isolated piece of functionality) is doing what we intended to do. That's all. Testing for integrated parts or testing for its performance or any other tests beyond that functionality is not included in unit testing. For example, If we wrote a class that's supposed to read inputs from files, unit testing for that class will test whether that reading functionality works for all kinds of inputs we intended to use.

You can certainly write unit testing codes after you write your code for that functionality. However, a much better and effective way of using unit testing is to write the test first. Yes it does sound strange. Why would you like to write a test if there's nothing to test on. Think about it this way. Wouldn't it be much easier for you to study for finals if you somehow had the final tests with you before you take the tests? You will exactly know what you will need to study. It's not the same but similar for software development. If you know what to test before even you write it you get a much better understanding of the code you are going to write. This is what happened to me for the labs. When I didn't understand the specification for the lab fully I read the tests that was already written and I could immediately get better understanding of what I should write for the lab. Besides, you will have to write the test anyways, why don't you write it first?

There's this great framework that will help you write unit testing codes easily. It's called CxxTest framework. It uses perl or python to automatically create test classes for your software. All you need to provide is a header file for your test that declares test class which inherits CxxTest::TestSuite super clas in the CxxTest framework. So for instance if you would like to write a unit test for readInput.h class all you need to create is a new file something like readInputTests.h. That has a readInputTests class which inherits CxxTest::TestSuite. Next you write methods starting with lowercase 'test' followed by any name you want for that certain tests. In that method you write test cases you want to test. Final step is to use cxxtestgen.pl to automatically generate .cpp test file. Cxxtestgen.pl will take header file and output .cpp file that can run the test. Usually you can automate this generation by putting it in the make file.

Unit testing is essential but it can be tedious to write all the test frameworks. With help with great framework such as CxxTest we mentioned, you can always easily change and add new unit test cases and automatically generate runnable tests on the fly.

Source Control, SVN


What is source control and why do we need it? Well If you are working alone on a project you wouldn't need to share the source code. However, when you work with a team sharing a source code becomes a necessity. In essence, a source control system is a software that help you share source codes among many different developers.

There are many software tools for source control and one that I use for my class is called SVN, or called Subversion. Here's the basic idea of how it works. You create a big place to hold all of your project files on a network server so that developers could access them from different places. This is called a repository. Each user do not directly access the project files from the repository. Each of them rather gets a copy of files on their local machines.

When developers make or change files on their local machines change does not effect files on the repository until developers commit their modified files. Each commit leads to increase in revision number. And you can easily compare changes through different revisions. A nice thing about commit is that it is an atomic operation which means if your commit gets interrupted for any reason( lost network connection for example) your commit operation will undo all the changes that it made so far. This atomic property of commit ensures integrity of project source files.

SVN simply is a control center for your project files. If a same file is modified and one developer tries to commit without knowing that the same file has been modified by other developers, the control system informs you with conflict message that there's a conflict on that file. This way you get a chance to see the changes made by others easily and decide accordingly. Without this control system you could have simply overwritten other people's work. Or others could do the same thing to your precious code.

There are three main notions in Subversion that helps successful control of your project. They are named trunk, branch, and tags. You can simply think of them as three major directories for your project with different purposes. Trunk is your basic development stream. Your main development is done here. You can tag a particular revision by copying any revision into tag directory. Branching is used when you want to do experiment or add new functionality to your project without effecting the trunk.

So far Subversion worked great for our team. However there are a few things you need to watch out for. First don't forget to add your new file to repository before you commit them. This happened to me many times. It is very easy to forget to add newly created files on your local machines. If you forget to add new files, no matter how many times you commit new files will not be committed. And your partner will never see that new file and will have to call you. Second, update before you start coding and always read log files to see what kind of changes have been made. Do not assume anything.

Group Projects


    To be honest, I really hated working in a group. This was not simply limited to programming projects. I preferred working alone. I always tried to stay away from any kinds of group work activities when I first got here. Perhaps it's because for most of my life, I was educated in a country where group work happens very rarely at schools and individual achievement is considered way much more important than group wise achievements. Now I am in the states and it seems like almost every single class I took had some sort of group projects. At first it was tough to dedicate myself to a group work. I definitely learned many benefits of group work but I still think there are many challenges. So here on my second blog I would like to discuss the challenges of group working.


    First challenge is rather physical. I am a shy person and I don't feel comfortable talking with new people whom I don't really know well. And it takes time to know each other and that can be a big time waste and sometimes it is very frustrating. When I work alone I only need to struggle with a machine. When I am working with partners there will be many more things added beside my buggy codes. I will have to arrange a new time to meet the partner if he or she does not show up. I will have to get angry if my partner has a big exam coming and he can't do anything until he's done with exam. Many social and physical problems can occur when working in a group.

    In one class I had two partners one from India and one from Somalia, before the group meeting I was starving so I ordered a pizza. When they came I offered the pizza and they all got offended by my kind offer. Both of them could not eat certain meat(can't remember the exact topping). I couldn't understand their response because first I was ignorant of other cultures and second I am Korean who can eat anything, even dog meats (don't get offended if you are a pet lover, we don't eat pets neither and I have a cute pet as well and I or my family didn't eat her for 12years). Again these kind of issues would have never occurred if I was working alone.

    Second challenge comes if two partners have different programming background or different level of experience. I once had a partner who had a great programming background. He seemed to know everything about the labs and projects and I just felt so useless sitting next to him watching him typing codes that I can't really understand. All I did for the group work was to write some comments or to edit the code so it looks pretty with proper line breaks and indentations. Oh and I also had a great chance to tar and submit the project. This was a big challenge for me. On one side I was happy that I didn't have to worry about getting good grades on labs and projects but on the other hand I was unhappy because I didn't learn.

    There are many challenges when working in a group. However I think if partners have similar skill levels, group work will give great benefits. Our first iteration was kind of small to bring out the benefits of group working. I look forward as projects get longer and harder. Our group will overcome the challenges and use the benefits of group working as much as possible.


| No Comments

     How time flies! It has been almost three years since I left the school in order to fulfill my duty as a healthy Korean soldier. I am finally back to the states this fall. My hands no longer hold K-2 rifle but I have my Lenovo X61s laptop on top of my lap (perhaps that's why it's called a laptop) to fight and win the battle of '3081W'.

     I have a very limited experience with programming languages in general. C and Scheme are the two languages that I know how to printout 'hello world' to the screen at least. Learning these languages I learned the importance of modular software design and writing effective comments.

     When writing code with procedural language such as scheme, modular design is even more important. Often times, when there's lack of modularity to the program whether it's for a small lab assignment or for a big final project, chance of rewriting the program from the scratch increases. Modular code design gives great advantage when there's change to come later. And I can assure you that change will come. Even with my little programming experience, changes occur all the times because humans are not perfect. Before I realized this I always tried to cram every line of functionality in to a single procedure (usually main() in C). And the code rapidly turns into a tangled stein, impossible to neither add nor alter. The only option left is to restart.

     Another great lesson I learned is the importance of writing effective comments. Good practice of commenting not only benefits for group working situations but also to a single person. At the moment of writing codes, I usually feel that I understand the code perfectly and therefore do not make any comments about what it does or how it does something. Later when I look at the same code I wrote I usually think: "who wrote this crazy code? My mom?" Without an effective comment any code can become a confusing puzzle-like-code that even the author has to solve the puzzle in order to understand what it's doing.

     In this class I really want to learn the language C++ and the development process using the language. I do not even know what class hierarchy is yet but I heard many good things about OOP programming languages. I really want to know why OOP has become so popular among other programming paradigms and want to see how the language is designed and functions well with in the context of OOP paradigm. In other words I not only want to learn about certain functionality of the language but rather it's application in designing and developing rather complex software.

     I am really interested in game development and it seems like C++ is the language that is often used for 3D game developments due to game's performance issues. For that reason, I am especially interested in C++ language and want to learn as much as possible. At the end of the class I really hope I can exploit the strength and usefulness of using C++ to build some moderately complex software. I know it would be very hard to even mildly appreciate the power of the language just in one semester with single project. I, however, wish the course will set a base to learn more advanced topics later in my career.

     As an international student, writing in English has always been a big challenge since I came to the states. And because of my major, I rarely had a chance to learn about writing in the discipline of computer science. So I am worried about this writing intensive course. I am sure later in my career there will be times when my skills to communicate or express my thoughts in writing becomes critical. Thus the second most thing I would want to get out from the class is how to write!

     I am very excited about many things that I will achieve throughout this busy course! I really look forward to it. Let the battle begin!

Recent Comments

  • sette075: the idea of writing tests first is interesting to me. read more
  • mart2514: I agree with you when you say that it can read more
  • saff0021: I liked your approach of looking at the test code read more
  • panz0031: Great idea about writing the tests first. I have not read more
  • norhe003: I think the idea of looking at or writing the read more
  • mehlh014: You brought up a good point of writing the tests read more
  • mandy014: The information in your blog is laid out nicely and read more
  • henc0017: A note on something you said in your post: By read more
  • Nicholas Ellis (ellis348): I like how you talked about how subversion interacts with read more
  • vonah001: Subversion is, indeed, a very useful tool! It gives us read more

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