Zum Inhalt springen

Just about .Net

It's just a blog about .Net…


Kategorie: English

A colleague of mine asked me this week how he can emulate special keys in Coded UI Tests. I knew that I wrote that in my book but actually did not find the official reference in the MSDN. That’s why I will provide it here again.

The Keyboard class provides different methods with which you can send texts or key codes to the UI element currently selected. Some of these methods also allow the use of modifier keys like Ctrl or Alt.

Keyboard.SendKeys(“{F4}”, ModifierKeys.Alt);

All special keys are shown in the following list. They are usually surrounded by curly braces and can be part of any string (see also the example above).

Key Code
Backspace {BACKSPACE}, {BS} or {BKSP}
Pause {BREAK}
Capslock {CAPSLOCK}
Delete {DELETE} or {DEL}
End {END}
Return {ENTER} or ~
Esc {ESC}
Help {HELP}
Pos1 {HOME}
Insert {INSERT} or {INS}
Numlock {NUMLOCK}
Page Down {PGDN}
Page Up {PGUP}
Print {PRTSC}
Scrollock {SCROLLLOCK}
Tab {TAB}
F1… {F1}
Cursor up {UP}
Cursor down {DOWN}
Cursor left {LEFT}
Cursor right {RIGHT}
Addition (num block) {ADD}
Subtraction (num block) {SUBTRACT}
Multiplication (num block) {MULTIPLY}
Division (num block)) {DIVIDE}

… and all I got was this lousy Christmas tree.

I like TDD and I like test automation. It is great to see the application growing with each successful test and to be sure that it will work even if a lot of changes are made on the code base. On the other I see (especially) TDD as a practice which is hard to master and I can understand people who drop any ambition because it feels intricate and some times frustrating in real projects.

One of these things is for example the advice to use baby steps to drive the implementation. I thing this advice is essentially to TDD and makes, from my point of view, the difference between Test First and Test Driven Development. Baby steps means, that you are not allowed to implement more functionality than needed by your tests. If the test expects a 1 as return value of your method, than your first step would be to simply return a 1. Your algorithm will also grow with each test you write and that’s why it is called Test Driven Development. This has also the advantage that the your tests get more robust, they are easier to change and to read, at least in theory.

Continue reading “All I wanted was a pyramid…” »

2010/2011 Roy Osherove wrote in his blog a sentence which summarizes an opinion you can still find in many other blogs: „MSTest is the IE6 of Unit Test Frameworks.“ . He basically says, that MS Test has a lack of functionality when it comes to unit testing and I agree with him with one exception:  I think it is not primarily a unit testing framework, it is a test automation framework but lets start with a comparison.

Continue reading “„MS Test the IE6 of Unit Test Frameworks?“” »

Do you know how to separate the knowing from the naive, the pros from the amateurs and the men from boys? It’s just by their reaction in certain situations. It’s the cold shivering and slight cough they get if you just whisper a single word, a word like “DeploymentItem”.

So what causes these reactions? Mortals would call it an attribute in MS Test. The most demonic one I have to add. If used, it defines external resources which shall be provided during a test run. Following test case shows the basic idea behind it. You say: “Deploy the file.” and Visual Studio deploys it for you, at least it should…

Continue reading “DeploymentItem - A tale of the unexpected…” »

I’ve spent the last weeks playing around with MEF which uses a feature of .Net 4.0 I didn’t know before: the Lazy class. A class which gives us a standardized, easy to use and thread safe way for implementing lazy instantiation.

Lazy instantiation describes a procedure of creating class instances on demand e.g. when accessing a property. The advantage is that you only invest resources like CPU time and memory if it is really necessary.
Continue reading “Lazy-Instantiation and the Lazy<T> - class” »