Testing against today’s date

(+1 rating, 1 votes)

May 21st, 2011

Suppose there is an automated test case for a report:

1. Generate a report for today
2. Check if the date printed on the report is today's date

The question is: how can this test case fail?

Read the rest of this post »

The PIN code: now you have it, now you don’t

(0 rating, 0 votes)

May 15th, 2011

I have the feeling that I’m getting old :) Last week I went to the supermarket to buy groceries. I was in front of the cashier when I took my credit card out from the wallet, put it in the POS and typed the PIN code. Surprisingly, I got an “Invalid PIN code” message. At that point I realized that the code I typed is actually the security code of something else, not of my card.

“Well… That’s not a big issue. I use that PIN everyday and shouldn’t be hard to type the correct one on the second attempt”, I told to myself. The second attempt ended with another “Invalid PIN code”. So did the third and my card got blocked.

The PIN code just vanished from my head. I tried to recall it, I know that it must be somewhere there, but I can’t.There are a lot of numbers in my head, some are of other cards and some I don’t know what they are. I even unblocked my card, tried 3 more codes that I thought might work and got the card blocked again.

Why can’t I remember the code? Meanwhile I ordered a new PIN…

Tool: f.lux

(+1 rating, 1 votes)

Apr 29th, 2011

Like many of you, I spend a lot of hours per day in front of the computer’ screen. Especially in the night, you might have noticed that the screen is really bright and you have problems looking at it. I had the same problem until I discovered f.lux (yes, the dot is part of the name). I’ve been using in the last 9-10 months and I really feel an improvement, is much easier to look at the screen during the night.

Basically, f.lux is a free, lightweight application that adjust the temperature the colors on the display in order to match the natural lighting conditions. While the sun is up on the sky, the screen displays normal colors. During sunset, a slow transition to night colors is made. After this, the colors are colder and, for example, white becomes brownish. It might sound strange but it really helps.

f.lux can br download it from the official website and it is available for Windows, Mac and Linux. On the same page, is a research on sleep and more details about how f.lux helps.

Default indexer and Reflection glitch

(0 rating, 0 votes)

Apr 22nd, 2011

I was writing some C# unit tests that had to use Reflection in order to set properties on objects, when I got into an interesting problem. I will provide a simplified version of the code I wrote, first the version without reflection, then my reflection version that had an issue and, in the end, the correct version.

TestClass is a class that has a property of type List<int>:

class TestClass
{
    public List<int> Value { get; set; }
}

Goal: create an instance of this class, set the property and print the second element in the list. Simple, huh? The code without reflection is:

TestClass c = new TestClass();
c.Value = new List<int>() { 4, 5, 6 };
Console.WriteLine(c.Value[1]);

Seems straight forward to use reflection for this, right? Here is my attempt:

//TestClass c = new TestClass();
object c = new TestClass();
//c.Value = new List<int>() { 4, 5, 6 };
Type t = c.GetType();
PropertyInfo prop = t.GetProperty("Value", BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(c, new List<int>() { 4, 5, 6 }, null);
//Console.WriteLine(c.Value[1]);
int valueToOutput = (int)prop.GetValue(c, new object[] { 1 });
Console.WriteLine(valueToOutput);

Can you see the glitch? I can tell you that line 10 throws TargetParameterCountException. You know why?

Read the rest of this post »

Dynamic tests with mstest and T4

(0 rating, 0 votes)

Mar 5th, 2011

If you used mstest and NUnit you might be aware of the fact that the former doesn’t support dynamic, data driven test cases. For example, the following scenario cannot be achieved with the out-of-box mstest: given a dataset, create distinct test cases for each entry in it, using a predefined generic test case.

The best result that can be achieved using mstest is a single testcase that will iterate through the dataset. There is one disadvantage: if the test fails for one entry in the dataset, the whole test case fails.

So, in order to overcome the previously mentioned limitation, I decided to create a text template that will generate the test cases for me. As an example, I will write some tests for an integer multiplication function that has 2 bugs in it:

public int Multiply(int a, int b)
{
    //This conditions are simulating the 2 bugs
    if (a == 0 && b == 1)
        return 100;
    if (a == 1 && b == 0)
        return -100;
    return a * b;
}

The classical approach (no dynamic test)

Without using any ‘hacks’, one could write the tests for the Multiply function in the following way:

//Tuple description <value of param a, value of param b, expected result>
private static readonly Tuple<int, int, int>[] TestData = new Tuple<int, int, int>[]{
    new Tuple<int, int, int>(0,0,0),
    new Tuple<int, int, int>(2,3,6),
    new Tuple<int, int, int>(1,0,0), //These will trigger one of the bugs
    new Tuple<int, int, int>(-2,-3,6),
    new Tuple<int, int, int>(0,1,0) //These will trigger one of the bugs
};
[TestMethod]
public void TestMultiply()
{
    foreach (var data in TestData)
    {
        Assert.AreEqual(data.Item3, Multiply(data.Item1, data.Item2),
                        "Failed for input ({0}, {1})", data.Item1, data.Item2);
    }
}

Running the test will surface only one of the bugs, the one triggered by the input (1,0):

This is not only bad because it doesn’t give a complete overview of the bugs but it also violates the principle of one assertion per test because more than one assertion could be triggered in the test case above.

The T4 approach (dynamic test)

Read the rest of this post »

Fun with Batch files

(-1 rating, 1 votes)

Feb 12th, 2011

It goes like this: create a small script that will take the files from a folder (only the top folder, not the sub directories) and will copy them to Program Files (32 bit). How hard can it be?

Well… If you have a programming background and you like to format the code then, such a task takes 1 hour, otherwise… 5 minutes.

So, I wrote a batch file (just part of it displayed here):

SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)

Which is incorrect. Can you spot the mistake?

I will highlight one of the lines for you, maybe you can spot it then.

SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)

Another hint: lines 5, 6 and 7 are incorrect.

Let me fix it and maybe you’ll see the problem.
Read the rest of this post »

Bug in SkypeGadget

(0 rating, 0 votes)

Jan 22nd, 2011

There is a bug in the Skype client that affects SkypeGadget. See status and workaround here.

Sorry for the inconvenience!

Christmas 2010

(0 rating, 0 votes)

Dec 24th, 2010

This is the first Christmas that I’m spending without my family. This is both good and bad. Is obvious why is bad but is good because I had the chance to know how is to do it different.

First of all, yesterday, which was my last for day for the year 2010, together with a few colleagues, we made snowmen in the MDCC campus. Those that saw them, categorized them as sincerely as possible as “the ugliest snowmen ever” but we are proud of them. The snow was really soft and it was impossible to make snow balls so we had to improvise.

Today, I celebrated Christmas together with 3 friends, 2 from India and one from Bangladesh. It was a little strange because I am the only one celebrating Christmas; for them is just free day :-) We cooked some Indian food – chicken, rice and something yellow that I don’t remember how is called – , drink some wine and laughed a lot. To my best surprise, the food was not as spicy as I was expecting and it was extremely delicious.

In a few days I’m going to Romania to see my friends and my relatives. However, I will not see my parents because they are in another country…

In the end, I wish you all:

And I leave you with a comic:

OneNote Anywhere

(0 rating, 0 votes)

Nov 8th, 2010

I like OneNote. I use it to store different code snippets and links to tech pages with useful information. It is not the ideal tool for doing this – IMO there is no tool, yet, that can replace a physical notebook – but I got used to it. Especially I enjoy the search feature because is impossible to do it on paper.

Until a few months ago, a solution for sharing the notebook between PCs was Mesh (or DropBox, or similar services), solution about which I wrote here. Since Office Live, this task was simplified – not that it was complicated before. With Office Live you can now save the notebooks online and edit them directly. Moreover, it allows sharing notebooks between computers connected to the Internet.

To do this you need a SkyDrive account (actually a LiveID). Then you can go on the website and create a new notebook. Give it a name and add information in it;do (almost) whatever you were doing in the OneNote client.

Now, if you choose Open in OneNote it will add that notebook to the application and… the best part… it will keep it synchronized with the live version.  You still have a local copy but if you lose it, only the changes since the last sync are gone – if  you are connected to the Internet then the last sync is, probably, 2 minutes ago. If you change the notebook in one place (on the website or in the local application), the changes will be reflected everywhere.

You can open the notebook on two or more computers and it will be updated on all of them. Even if one of them is offline, the changes are stored on the Internet and when you connect, you get the updated version.

Where is Victor?

(+1 rating, 1 votes)

Sep 18th, 2010

Hello there,

It’s been quite a while since my last post. A lot of things changed in my life since then; well, a little before that post. First of all, I moved to Denmark. Here, I’m doing an internship at Microsoft (Development Center Copenhagen). More specifically, I am a SDET working with the Dynamics AX team. Even more specifically, I test the developers tools from Dynamics AX.

Secondly, in 3 months, I moved two times. First from Netherlands to Denmark and then I switched place one more time because I was too far from my workplace. I really hate this activity but nothing can be done… And… I will move once more before the end of the year :(

I also started my master thesis project. (Hopefully) The outcome will be a really nice tool for Visual Studio (but not only). It will help developers and testers to find faster/reduce the number of bugs and will reduce the development time/costs. That’s all I’m revealing for the moment.

Least but not last, Copenhagen. In some sense, the city is both beautiful and ugly. Is a strange combination of modern and classic. A classical looking city with parks, rivers, boats, bridges and building with the same architecture, but having high speed trains, modern buses, shops and blinking commercials – that’s Copenhagen. It is filled with attractions (museums, theme parks, shopping places, events) but is really expensive (ex: the price for a beer in a crappy bar starts at 4-5 euros).  I didn’t have too much time for sightseeing but I managed to make a panorama picture (see below).

Read the rest of this post »

« Older Posts Newer Posts »