As we are working on the next set of features for Typemock Racer, the threading related test framework, I think it will be nice to know what features and thread constructs people use the most in their applications. The poll below uses flash, if you can't see it.

Please fill it in and we'll see what people use the most! While I'm here, I may as well ask you another couple of questions that need re-examining. Which mocking framework (if at all do you use?) and which unit test frameworks do you use?

Posted by RoyOsherove | 5 comment(s)
Filed under: ,

Sasha and Alon have released an open source project called "Non Paged CLR Host" which has the following benefits(quoted):

  1. Applications will benefit from no paging during normal operation.  Even if other applications are actively allocating memory, allocations performed under the non-paged CLR host will be locked into physical memory.
  2. No paging will occur when the application is idle, providing a great benefit to low-latency processes such as GUI applications (even if the user has fallen asleep in front of the monitor).  The normal working set management scheme employed by Windows will not affect processes running under the non-paged CLR host.

That's Pretty cool. I've had the pleasure of working on a project with both of them, where CLR memory boundaries are constantly challenged. I wonder if it could benefit from such a piece of code!

PS

If you're not following sasha's blog - you really should.

Posted by RoyOsherove | 2 comment(s)
Filed under: ,

Here's a sneak preview of the upcoming Typemock Racer product, which I'm currently working on. We should be out in private CTP in a couple of weeks I hope.

Typemock Racer tries to solve one huge problem for developers working in multi threaded environments: Detecting code that can result in deadlocks or race conditions. It does this by providing a framework API which you can use in your tests (under NUnit for example), that allows you to execrise your code under test until it finds a deadlock or times out.

Here's an example of how you'd use it. Consider the following class which has two methods, that if run by two seperate threads, can result in a deadlock condition:

image

At some point in time the threads could execute such that thread 1 is waiting on resource b, which is held by thread two , which is waiting on resource a, held by thread 1 - a pure deadlock.

Given this class we can write a test that looks like this:

image

The ThreadTest class has an "AddThreadAction" method that receives a delegate. you can use it to invoke your own code, it will be invoked in a different thread. IN this example we are creating two threads, each one running a different method on MyClassWithLocks.

We can just right click and run the test with TestDriven.NET to recieve the following results:

image

The output states that there is a deadlock that was found, with the exact steps that happened (with line locations) to reproduce this.

It currently only works with lock (monitor.Enter\Exit) but will support all locking constructs in .NET.

 

What if the methods you point to create their own threads? Like this:

image

Here is the output that you'd get if you run this test:

image

When I first heard of Audible.com (in one of the TWiT shows) I was very excited that I could get lots of stuff to hear on my mp3 player.

Then I started using it. And was terribly annoyed.

  • I couldn't use the downloads on my Zune device because of Silly DRM issues
  • Living in Israel, some audio books (like colbert's book, or Hodgman's book) are blocked for me to purchase.
  • I can't back up or convert my files or play them freely because of the DRM protection, even though they are mine and I have purchased them fairly.

I looked for a long time for a way to get the files DRM free. There was one way but it required to have an old version of the audible software installed. They have fixed that "bug" and not the only way is for people to burn 9 hour books on 11 CDs and then rip them to mp3. and that is a big pain.

So, Audible, this is for making me feel a second class net citizen, as well as many others.

I finally found a way to get my fully paid for audio files without DRM and without needing the bloody audible download manager (which is actually the thing that puts the DRM on the files!). I created a little program that helps you download the files directly to your computer without the audible software.

To make sure you understand - you can only download your own purchased books using this tool just like the standard way. the only difference is that they will not be with DRM so you can back them up and move them around and convert them as much as you want.

If you're interested in how my workaround works (you're a geek) it is in the bottom of this post.

How to download your paid-for DRM free audible books

  • Download my little program: Audibler.zip and unzip it.  (5k). You need .NET Framework 2.0 or above
  • Login to the audible website normally and go to "my library"
  • Go the line where the book you want to download is, and right click on the button that says "Download it". The copy the link url in the button to the clipboard.
  • Run the audibler.exe file that you unzipped earlier.
    • The link you copied to the clipboard should be shown on the top screen.
    • image
    • Click "Translate and start link" to have your default browser start downloading the file directly.
    • Or you can click "translate" and then copy the URL on the bottom of the dialog to your browser address bar.

 

How to convert the downloaded .aa files to mp3

you can use your own favorite conversion software from .aa to .mp3. below is how I am doing it.

  • Install DbPowerAmp power pack and the directshow plugin (http://www.dbpoweramp.com/) (It seems to work really fast)
  • Download and run the Audible Media Player Filter and install it, if you are running the latest version (5.0) of audible manager.
  • if you are running version 4.0 this is not needed.
  • after downloading the file you wanted,  right click on the file in windows explorer and choose "covert to" and convert to mp3.
  • if you don't see any "convert to" menu,
    • You may need to go to "c:\Documents and Settings\[YOUR_USER_NAME]\Application Data\dBpoweramp\directshow.txt and add '.aa' without the quotes as a new line in the middle of the file somewhere.
    • then go the the start menu and run dbPowerAmp configuration and click OK on the dialog. then try again.

 

How this works:

To find out what happens behind the scenes I used the free Fiddler2 tool from Microsoft that can trace http communications. When I ran it along side the audible download manager I could see the request to download the special file URL. From there it was a simple matter of looking at the web page, seeing how the links are built, and changing parts of the URL to fit what the Download manager was requesting.

It uses a simple regular expression to find out the parts of the URL (let's see how fast they change it..) and then replace them with what the software needs. You can also just open Reflector and look at audibler.exe to see exactly how simple it is.

Posted by RoyOsherove | 21 comment(s)
Filed under:

It's interesting to see the other mocking frameworks as they grow into maturity. Especially Moq which has been getting loads of new features recently. The latest one is something which makes me feel a bit weird after reading all the things people fear in Typemock Isolator:It seems that  Moq now allows mocking protected fields.

What's really interesting is that Daniel has chosen to actively allow this, and hide the feature at the same time, as well as put it under a strict optional request:

you have to opt in for each code file where you'd like this ability by adding a special imports statement.

So, the questions I have are:

  • What happened to "if it's not testable it's a design smell"? Is this a compromise or have people figured out that good design can take many forms, with tools being left to do the hard lifting?
  • If you're going to add powerful "non classic" mocking ability to a framework, does adding it as a special "opt-in" feature make it OK? (this is what we are talking about doing with Typemock Isolator)
  • If tomorrow Rhino.Mocks were to add the same feature or something even more powerful (statics?) how would people treat that?

In the previous post I introduced Depender, to help find dependency issues in your code (usually for testing).

I've added extensibility to it so that you can write your own rules. If you download depender there will also be a "src" directory in the zip file, which shows how the current rules it uses were built.

it should be really easy to created your own rules. Just :

  • create your own assembly that has a name ending with ".Rules.dll"
  • Implement IRule in your class, or, if you want to parse the contents of a method, inherit from MethodParserRule.

your rule will be automatically loaded according to the assembly naming convention and its interface.

here's how a simple rule looks:

 

public class FindOverridableMethodsRule:IRule
{
    public void Check(MethodInfo info, Dependency parent)
    {
        if (!info.IsFinal && (info.IsVirtual || info.IsAbstract))
        {
            parent.Add(new Dependency(string.Format(" {0}() can be overriden", info.Name)));
        }
    }

    public bool CanCheck(object obj)
    {
        return obj is MethodInfo;
    }

    public void Check(object obj, Dependency parent)
    {
        Check(obj as MethodInfo, parent);
    }
}

 

 

and here's a rule that parses the contents of a method:

 

public class FindStaticMethodCallRule : MethodParserRule
{
    protected override void DoChecks(MethodBase mehodBeingChecked, MethodBodyInfo methodBody, Dependency parent)
    {
        foreach (ILInstruction instruction in methodBody.Instructions)
        {
            if (instruction is InlineMethodInstruction)
            {
                InlineMethodInstruction line = instruction as InlineMethodInstruction;
                if (line.Method.IsStatic)
                {
                    string message =
                        string.Format("Static method call {0} on {1}", line.Method.Name,
                                      line.Method.ReflectedType.Name);

                    parent.Add(new ProblemDependency(message));
                }
            }
        }
    }

}

Posted by RoyOsherove | 2 comment(s)
Filed under: ,

Update: Here's how you can extend Depender with your own dependency rules

Depender is a tool that I created to illustrate several concepts both for my book and both for my training classes. I think it should prove valuable (as it gets more and more features) to anyone who is trying to write tests for existing code.

 

Depender allows you to load an assembly and inspect the types within it according to very simple rules. the main question on my mind and I run it is: "How easy would it be to test class X?". Depender will list all the classes in the assembly and for each one will try to detect possible testability problems (non decoupling) and places where you might be able to "inject" your own implementation (calls to virtual methods, fields that are interfaces or types who are not sealed..etc..)

 

so you can:

  • see places where you might want to refactor your code or use a tool like Typemock Isolator
  • see places where you can already use "seams" to inject behavior into your code without needing to look up the source code manually.

here's what the main screen looks like when loading an assembly:

image

the type "RealLogger" is marked in red because it contains calls to static methods. double clicking on the type's node will load a separate window just for this type:

image

 

I will be adding more rules and also releasing the source so that other people can help develop this. for now I just want to get it out there and see what people think.

possible futures:

  • Make it command line driven so it can run in your CI builds
  • Make it give "scores" to assemblies or types on testability and decoupling
  • Make it add "suggestions" on how to fix decoupling issues
  • Make it create the base diagram for my test feasibility matrix

Download Depender from here.

My kid is a geek at 18 months:

 

image

and also an amazing architect with a sense of (porcupine) humor:

image

Posted by RoyOsherove | 1 comment(s)
Filed under:

If you're in norway, this might be of interest to you. I'll be doing two 5-day courses on TDD and Unit Testing in august and december. here are the dates and links to the full course outlines:

Courses are currently limited to 20 attendees and are mainly exercise driven (working in pairs). I'm only planning to do these 1-2 times a year for scheduling reasons. as far as I hear the august course is already half full.  These are hands on, .NET centric classes, with little theory and mostly practice.

Test Driven Development in .NET Master Class

Date:  August 18

Location: Oslo

Register here

 

Test Driven Development in .NET Master Class

Date:  December 1st

Location: Oslo

Register here

Posted by RoyOsherove | with no comments
Filed under:

We just released Typemock Isolator 4.3 (here is the blog post with details). It's an awesome product but I envy the speed and ease with which oren can change his syntax (it's nice to work alone!) . I can tell you that the next version of Isolator is going to have a new syntax that is more towards the Arrange-act-assert meme (but you could still use the old one if you wanted to) plus lots of cool goodies.

the new version has full support for Ivonna (for ASP.NET webform testing in process) and we have removed .NET 1.1 support. Many other things changed are listed here.

Posted by RoyOsherove | with no comments
Filed under: ,
More Posts « Previous page - Next page »