Browse by Tags

All Tags » HowTo (RSS)

Getting started with Fake Objects – Part 3: Verify that a call has been made

If you haven’t read the other posts in this trilogy - you might what to have a look at them about now: Why fake is better then mock How to create a fake object Let’s begin the third part of this tutorial where I’ll explain what to do when we need to test that a method has been called. The problem at hand If you remember the code from the previous post we have UserService and we need to create a new user. In the last post I’ve explained how to fake the UserRepository so it will return the value we...

VS2010 Tip – How to run unit tests in 64bit process

One of the reason I used to prefer NUnit was that I could run my tests as x86 or x64 depending on what I needed. I was always strange that Microsoft unit testing framework didn’t have this ability. Luckily for use it seems that Microsoft heard our pain and decided to enable us to run our unit tests in 64bit context. And its very simple to enable – once you know it’s there. Just head to the test configuration (yep – Local.testsettings ) and under Hosts you can set if to run the tests as a 32bit or...

VS2010 tip: How to run unit tests in parallel

Running unit tests can take some time – at Typemock we have about 4,000 unit tests and running them takes 15 minuets. If you always wished it to take half the time (or a quarter of the time) – wait no more! Visual Studio 2010 has a hidden feature called parallel test execution – which means that you can run four tests at the same time on your quad core. Before you start make sure you don’t have any data collection/profiler active. Just go to the test settings (Local.testsettings file) under Data...

Getting started with Fake Objects – Part 2: How to create a fake object

In the previous post I’ve explained (briefly) what are fake objects and why they should be used – if you haven’t read it yet – I suggest you do so now. In  a nutshell fake objects are used to break dependencies in unit tests to make the test faster, predictable and enable you to test the un-testable. In this post I will show code! in fact we’re going to use isolation (Mocking) frameworks to create our very first fake object. I apologize in advance for using C# for my examples – just keep in...

How to collect NUnit test results in TeamCity

I’ve been using TeamCity for some time now and I love it - It’s easy to install and use. TeamCity can also run unit tests using several test frameworks and collects data about the tests runs as long as you’re using one of the supported build scripts (e.c. NAnt or MSBuild) – from how many tests have been run to a list of problematic unit tests that tend to fail. All of this is nice and dandy but what if you happen to use a different build script tool – one that doesn’t have TeamCity integration? At...
Posted by dhelper | with no comments

How to unit test “un-testable” code (in a nutshell)

Not being able to unit test an essential scenario is one of the reasons developers stop unit testing their code. In fact most of the time when a team decides not to use TDD (Test Driven Development) is because it seems as if they won’t be able to test the production code using unit tests. Most of the time this is just wrong! Of course some scenarios are more difficult to test but in most of them it’s not impossible, just a matter of technique and tools. First – understand the problem Unit tests are...

Poor developer’s memory profiler

Some tools save you money. The rule of the thumb is that if you save X days using the tool and your salary is Y dollars (or whatever you get paid with) per day then the tool is worth X times Y - it’s that simple. Over the years I’ve used several tools to do performance profiling but I’ve never quite found a good memory profiler. Although there are some solid and effective memory profilers for .NET - they tend to run forever and the results they supply are less than optimal, using a memory profiler...
Posted by dhelper | 4 comment(s)

How to use a printer from windows7 when you don’t have the needed device driver

At office we have a Xerox printer that don’t have a driver for windows7 (yet?), but I still manage to print from it without any hassle. How – simply by using the incredible XP Mode. The bane of the last two windows OS (Vista and Win7) was lack of driver support, although win7 has better support you can still find several vendors that still don’t have drivers for their products especially for the 64bit OS version. Luckily the new Virtual PC/XP Mode supports external devices and setting a new hardware...
Posted by dhelper | 3 comment(s)
תגים:, ,

XmlWriter that automatically close elements using IDisposable

System.Xml.XmlWriter provides an easy and lightweight way to write xml strings, unfortunately it has a little gotcha. consider the following xml string (borrowed from IronPython in Action ): Using XmlWriter the following code is needed to create that string: Keep in mind the fact that the code above only creates 5 lines of xml, and as you can probably tell it has a very distinct overhead – for each element/document created you must add a WriteEndX statement, the code quickly becomes unreadable and...
Posted by dhelper | 4 comment(s)

Learn to write better code

If you don't make mistakes, you're not working on hard enough problems.  And that's a big mistake.  ~F. Wikzek It was when I found out I could make mistakes that I knew I was on to something.  ~Ornette Coleman While one person hesitates because he feels inferior, the other is busy making mistakes and becoming superior.  ~Henry C. Link I consider myself lucky, in every place of work I had a mentor that helped me improve and taught me something that made me a better...
Posted by dhelper | with no comments
תגים:, ,

What to do when DebugBreak won’t let me debug on windows7/Vista

A curious problem that I had today at work: I’m working on a component that suppose to run as another “service”. Because of the environment limitations I could not  just debug using visual studio (F5) and had to set my debug points manually using __debugbreak. I recently installed Windows 7 and so far I enjoy using it until today instead of showing the usual dialog that asks if I want to Debug the program I got a message telling me that the application has stopped responding. No matter what...
Posted by dhelper | with no comments
תגים:, , ,

How to write a simple DXCore plug-in

DevExpress the creator of Refactor and CodeRush two great visual studio productivity tools provide a free library called DXCore that can be used to create rich plug-ins that can extend visual studio the same way their commercial products do. Until visual studio 2010 will be widely developers can use DXCore to extend visual studio and provide integration functionality without messing around with DTE and GUIDs. In this tutorial I will explain what is needed to write your first DXCore plug-in Prerequisites...

Fix - Visual Studio crash when running MSTest

Today during work I had a very annoying issue - whenever I've run the project unit test suite (using MSTest) Visual Studio disappeared. This is the first time I saw it crash like this without any error message or even an exception it just vanished. I've gone through the regular routine of restarting windows and re started visual studio but it didn't help, my helpful co-worker even suggested that I re-install visual studio 2008. Due to the fact that installing VS2008 would have cost me...
Posted by dhelper | with no comments

How To run as 32bit executable on a 64bit machine

One of the problems I've encountered while working on a x64 machine is that I need to run NUnit as 32bit if I want to run a test assembly that was compiled as a x86 assembly. In fact I had several similar occasions when I needed to run applications on my computer as 32bit executables. For this exact purpose a CorFlags Conversion Tool (CorFlags.exe) tool was created. Corflags was shipped with .NET Framework SDK (2.0) it is a tool that allows the user to view and configure the corflags section...
Posted by dhelper | 2 comment(s)
תגים:, ,

How to remove a setup package with a known uninstall bug

Today was the 2nd time I managed to cause a machine at work to not be able to uninstall the project I've been working on. During installation tests I "accidentally" deleted part of the registry and resulting in not being able to uninstall the MSI (because it wasn't there) and not being able to install a new version of the project ("project already exist") - AAAAAAAAAAHHHHHHHHHHHH! I've tried using some of the uninstall tools (i.e. Revo Uninstaller ) and even considered...
Posted by dhelper | 1 comment(s)
תגים:,
More Posts Next page »