Sunday, February 7, 2010

Designing for testability: The good, the bad and the ugly


On February 13, 2010 in Microsoft premises in Prague, there will be a series of ongoing short presentations about .NET.


Gil Zilberfeld will lecture online @ 13:30 CET “Designing for testability: The good, the bad and the ugly”

If you design your application for testability, you’ll have a better architecture, components will be decoupled, and the sun will rise every morning. But is testability really the goal? You will want to watch out from taking it too far.
It’s time to talk about what designing for testability really is – the good and the bad. Your architecture and your project can benefit or suffer from the choices you make. In this webinar session, Gil Zilberfeld from Typemock is going to discuss the pros, cons and alternatives.

Gil Zilberfeld has been in software since childhood, starting with Logo turtles. After 15 years in commercial software companies, he has vast experience in development and development practices. Currently Gil is the Technical Evangelist of Typemock, promoting unit testing and some incredibly cool tools.

Sweepstake 3rd week in a row, Next drawing this Wednesday The 10th


Free Isolator 2010 Every Week

 

Welcome to the Easy Unit Testing Family. By now you are probably Following Typemock @ Twitter 

AND only for that you will be included in every Wednesday Drawing from now until the End of February, unless you  already won or will win Before :))).

The rules are very simple:

  1. make sure that you are following us on Twitter
  2. To finalize your registration please Tweet from your personal twitter account

Just entered to win an Isolator 2010 to enter & keep up with latest unit testing news, follow @typemock & RT

http://bit.ly/7SVQkx

 

That’s it!

You may Email us your contact information to Social@typemock.com

Good Luck!!!!

Friday, February 5, 2010

More from this week Typemock TV

Typemock TV

“This Week In Testing” Episode 12: 3 Guys, a Girl and a Bunny (Part 1)

It’s amazing what you can do with tripod. We’re not going to show you that.

Instead we’re going back to animal discussions. And there’s some some testing related issues as well.

Enjoy our new settings, beer and crew. We did.

Part 1 is here.

This week in Testing Part 1

Thursday, February 4, 2010

How many tests do we have for Isolator?

we’re big fans of using FinalBuilder and TeamCity, and we’re big fans of testing and continuous integration as well, so it’s only fitting that you see a sneak peek at what our continuous and nightly build runs contain in terms of testing:

image

yep, about 10,500 tests for the nightly build.

Wednesday, February 3, 2010

“…I want Typemock. It makes life so much better.”

 

This past weekend I received an Email from Roy Oshorove, the email was CC’d to the entire company and the message:

“read how he saw it. also - he gives a great idea for an intellitest feature. see if you can figure out what it is!” and he attached a link to a Blog Post Written By Brandon D’Imperio  “Unit Testing Made Easy with the power of typemock”

It was pleasure to read and as our Development Manager said, it was almost emotional to get an outside perspective, that we not only help the developers with our great tools, but that our product is exactly the product that they were looking for, everything they can ask for and more…

Typemock,twitter

Brandon wrapped up his post with these words

“I did not have to alter my code to fit the tests. I did not have to think about testability when writing the code. I did not need any special assembly attributes. I want TypeMock. It makes life so much better.”

 

 Doron Peretz,Typemock

 

and our Development Manager, couldn’t ignore it, and Emailed all of us

“This is so exciting I am getting emotional. This is exactly the vision we had in mind to lower the barrier for people who want to unit test with our tools. Great job, team!" said Doron Peretz - Development Manager @ Typemock

Thank you guys for sharing your success stories with Typemock

Have a Great one and don’t forget to follow us on twitter

2nd Twitter Sweepstake Drawing

 

Hi guys,

We are happy to announce our 2nd winner in the Twitter Sweepstake, and this week the winner is :

Dan Forsyth @DannOh from Burlington Ontario, Canada.

We already announced the winner, and we are happy to Welcome Dan to the Unit Testing Family…

Typemock,twitter

“Thanks Tal, I'll be sure to send out a tweet. I love the product and have been using it on a project recently, be great to have my own license. Dan”

You are Welcome!!!! And for the rest of you guys, there is still a chance to win in our next Drawing, that will take place a week from today on February 10th 2010.

 

Good Luck

And Don’t forget to follow us on twitter.

Tuesday, February 2, 2010

Brian Mains on Focusing on Testability - An Example

Brian Mains wrote a nice post on how to modify the code for better testability. Now, it’s not  that the code is not nicer, but testability hasn’t changed – it was testable before and it remained so after.

I’d like to repeat Roy’s comments on the blog:

we focused a lot of effort in making sure that you need to write very little code to make things testable where possible.

in this case the same result can be achieved with:

//Arrange

Isolate.WhenCalled(() => HttpContext.Current.Handler).WillReturn(page);

var fakeTraceContext = ((Page)HttpContext.Current.Handler).Trace;

//act goes here

Isolate.Verify.WasCalledWithAnyArguments(() => { fakeTraceContext.Warn(null, null, null); });

//this works because all fakes are recursive with Typemock - so the trace, handler props are already fake. just use them as you with to verify calls.

Recursive fakes are very powerful:

  • They allow you to write less test code and still achieve the same goal.
  • You don’t need to set behavior on what you don’t need
  • Tests are more robust, because there’s less to break

And at the end of the day, remember that testability is not the issue. It’s your code – and because you’re going to live with it for a long time, make sure you design it they way you want.

Monday, February 1, 2010

Introduction to Isolation

Well, it’s been a while since I’ve gone back to basics. But let’s do that, shall we? Why do we need isolation anyway? Step into my time machine, will you?

It was about 4 years ago, when I decided to try TDD (Test Driven Development). I was a project manager at the time, and I had a rule – never test anything on your team, before you try it (on) yourself. I was writing a communication server at the time, and thought – hey, why not?

Starting was easy. I added a couple of interfaces, checked that the object is created correctly. And then I got to the heart of the matter – the component used MSMQ as a messaging infrastructure. Sending a message to the queue was easy. Checking that it got there – well that’s another story.

My success for criteria for my test for sending a message was to check that the message arrived. And it arrived. Sometimes before the test ended (success) and sometimes after (failure). You see, MSMQ has a mind of its own (also known as asynchronous behavior). I couldn’t control its behavior, so I had to replace it with another object I could control. This was my first mock object.

Mocking is generally an overloaded term (that’s why I like isolation better). But at its base - it’s about changing behavior. Which behavior? Dependency behavior.

Let’s look at my class:

public class Server

{

public void SendMessage(MessageQueue queue, object message)

{

queue.Send(message);

}

}


I need to send the message to the queue. But, like I said, queue (which is the dependency of Server) sometimes behaves funny. And we don’t like funny, we like dependable. Let’s change the signature a bit:



public class Server

{

public void SendMessage(IMessageQueue queue, object message)

{

queue.Send(message);

}

}



This time, I’m not sending a MessageQueue object. Instead, I’m sending the IMessageQueue interface, which looks like this:



public interface IMessageQueue

{

void Send(object message);

}

Now that I can inject any object implementing the IMessageQueue interface. For example, my real Message Queue object looks like this:




public class RealMessageQueue : IMessageQueue

{

var queue = MessageQueue.Create("AnyQueue");

public void Send(object message)

{

queue.Send(message);

}

}



But another, a fake message queue object can look like this:



public class FakeMessageQueue : IMessageQueue

{

public bool messageWasSent = false;

public void Send(object message)

{

messageWasSent = true;

}

}



As you can see, with the FakeMessageQueue, I can actually test that the message was sent:



[TestMethod]

public void Send_StringMessage_MessageWasSent()

{

var fakeMessageQueue = new FakeMessageQueue();



var server = new Server();

server.SendMessage(fakeMessageQueue, "message");



Assert.IsTrue(fakeMessageQueue.messageWasSent);

}

And that’s the whole idea behind isolation- the ability to change behavior. Today I wouldn't advise to go down the manual way – Read here why you should, nay, must use an isolation framework. But sometimes, it’s nice to go down memory lane, see how far we’ve come…

Sunday, January 31, 2010

Next Drawing for the FREE Isolator 2010 This coming Wednesday February 3rd.

Thank you for Following Typemock @ Twitter - we welcome you to the Easy Unit Testing Family.

You will be included in every Wednesday Drawing from now until the End of February, unless you won already or will win Before :))).

The rules are very simple:

  1. Start following us on Twitter
  2. To finalize your registration please Twit from your personal twitter account

Just entered to win an Isolator 2010 license to enter & keep up with latest unit testing news, follow @typemock & RT

 

http://bit.ly/7SVQkx

That’s it!

You may Email us your contact information to Social@typemock.com

Good Luck!!!!

Saturday, January 30, 2010

.Net coding discoveries, focused on reusability: UnitTesting made easy with the power of TypeMock

.Net coding discoveries, focused on reusability: UnitTesting made easy with the power of TypeMock

Thursday, January 28, 2010

First Twitter Drawing….And the WINNER IS:

Yesterday we did the first drawing for Typemock twitter followers. @ 1:00pm Eastern Time, The Happy Winner received an immediate notification, and gave us the permission to share his information…

The Isolator 2010 license winner is Warren Schaefer @maniacD

Everyone else is entering the next drawing on Wednesday February 3rd.

If you haven’t done so already, start following Typemock on Twitter – we promise to welcome you to the Easy Unit Testing Family.

And you will be included in every Wednesday Drawing henceforth until the end of February, unless you will win Before :))).The rules are simple:

1. Start following us on Twitter

2. Twit from your personal twitter account:


I entered to win an Isolator 2010 license To enter and keep up with the latest unit testing news, follow @typemock & RT http://bit.ly/7SVQkx



That’s it!

You may email us your contact information to Social@typemock.com

Good Luck!!!!

“This week in Testing” Episode 11 (Part 4)

Is this the end? Yes. Well of this chapter anyway. We’ll have something else next week. But don’t fret – Doron and Dror still make sense.

Go watch part 4, after you do your homework on part 1, 2 and 3.