One of the questions I often ask during interviews after candidates write code, is to come up with test cases for unit testing. This question helps me to tell experienced and good developers apart from non-experienced ones. Non-experienced developers would have test cases based only on code coverage. It isn’t wrong, just insufficient, because if there is a condition that the code is not already checking, the tests will not surface the defect.

Let me explain with a simple example. Let’s say here’s the Java code for binary search.

public void Node {
    public int value;
    public Node left;
    public Node right;
}

public Node binarySearch(Node root, int value) {
    if (root.value == value) {
        return root;
    } else if (root.value < value) {
        return binarySearch(root.left, value);
    } else {
        return binarySearch(root.right, value);
    }
}

If I only have test cases for the above code based on code coverage, I will have the following test cases:

  • value is at the root
  • value is on the left subtree
  • value is on the right subtree
  • tree is one-sided (only have left children or right children)
  • tree is zig-zaged

Everything looks good right? What’s missing here? What about if the tree is null or empty, or that the value does not exist in the tree? Ops. It’s not in the code, so it’s not covered in the test cases.

Test cases need to be designed independently of the code in front of them. Yes, it is important to cover all paths of execution, but it’s equally important to test the correctness of the code based on requirement, including all boundary and error cases.

So next time, think outside the code.

Thought of the day:

It is never about just the complex and powerful algorithms, or the amount of data involved, or just the pretty UI that makes a great application. It takes vision, insight and planning, takes solid design, implementation and execution of all the various parts, then integrate them into a harmonious piece. And of the whole time, a mind that focuses on the ultimate customer value and customer experience. It takes technology, knowledge, experience and execution to make a great application. The people element is often time far more important than the code and technology.

We just moved office to a new building this Monday.  Because the company is growing so quickly, this is already the 3rd office since I joined less than a year ago.

It seems like every time we moved, the worse the building situation is.

Our team is expanding quickly. We will have 3 FTEs and 2 interns joining in the next two months. But the new place we just moved to does not look like there is much room for more people. Our team is put in the same “team room” as another team, having 5 people there in one room. The room feels crowded, either too warm or too cold since there is no window anywhere, just walls all around and a door at one corner. They are planning to put 2 additional people in the same room.

Really? How did whoever that was who measured the room to say it was a 8-people room in the first place? The team room is about the same size as 4 cubicles right outside!

I don’t mind open office; in fact, I like open cubicles. It increases communication. Having people in a dense room is a different matter. The air vent in the room is always very loud, hissing. Without the air, the room is too warm. With it, everybody has to put headphones on to block out the hissing. Now try having conversations over that noise, and try to be the other people who aren’t part of the conversation and don’t have headphones on. I don’t mind people talking there, I just wish there’s a better office environment in general.

Another problem of the current office is that, usually I like to keep my ears open for other people’s discussions so I can learn, or to contribute. With the noise all around, I had no choice but to put on my headphone full time. I can’t hear any discussions any more.

There is no natural light inside the team room. Inside, we cannot tell if the day is getting dark or not, if we are the last in office or not. As a result, everybody stayed later than usual this week.

It’s kind of strange that we have just been there for 3 days, but so far, I have heard more complaints than praises, even about the bathroom and elevator. Maybe we are spoiled. The first office when I joined was on 10th floor, overseeing Seattle downtown, had a great view of the Space Needle. It was very nice, but maybe we did not appreciate it enough and therefore we are damned now.

What is the use of complaining and venting? Well, we sure are hoping to move to somewhere better, even if it just solves some of the problems, such as having proper office space and enough desks for our about to be expanded yet again team.

Good thing about moving? Cleaning and tossing things away. What not to like? Rearranging furnitures, reconnecting computers, and losing one whole day packing/unpacking/rearranging/getting equipment back online. Deadlines approach at the same rate, completely ignoring the fact that we have just lost a working day being unproductive.

Life goes on.