Self Expression

9 02 2009

Hi

I was just watching a Channel 9 session about Open Space, an idea where attendees to a conference come together to discuss topics they find interesting. The thing about this is that it’s about the audience providing the content rather than the key speakers and that means the audience get to express their selves.

It reminds me of how important it is to people to have an avenue of self expression. Whether it is the colours we wear, the music we listen to, or what we say, pretty much every part of our lives is impacted by this almost primal desire to express ourselves. The same is true within software.

In software, many people are influenced. Whether it be the development team, the business people who fund it, the customer, or the end user. Hey, even the people who have nothing to do with the software but are affected by the business processes the software supports, everyone is affected in some way by software. But this is where these two ideas come together.

How are people expressing themselves through this software? Thinking about how people will express themselves while using the software is so very helpful in making great software. Why? Because it allows people to do things their way, to demonstrate their understanding, and to allow others to know who they are.

How does your software allow your customers to express themselves? Does your software allow your company and the people within it to express themselves? Human beings are relational and expressive. Keep this in mind when designing your next user experience.

Kind Regards
Glenn





Google Chrome

23 09 2008

As part of the internal work here at DWS, I tried Google Chrome. What I was looking for was another browser that did in-line spell checking; Firefox is the other one I know of and there are likely more. Interestingly, IE doesn’t provide this functionality.

As I looked around this new browser, I went through the comic presentation on the design decisions. It’s quite inspiring and the browser does well for their approach. What I want to talk about today is the sort of thought that went in to this browser.

Threading vs Multi-Process

A stand-out decision was to make each tab a different process. IE, in comparison, treats every tab as a separate thread. If you’re not quite familiar about topics this close to the silicon, keep reading, I’ll expand on how very different these two approaches are!

Threading is all about one process doing multiple things. Threading is often used on the Windows platform. It is a historical decision as much as a technical decision. Some of the key considerations about this are:

  • If the master thread dies, all threads die
  • There are difficulties to be overcome when threads begin talking to each other or using the same memory space
  • Threads have to be monitored and managed
Multi-processing is quite different. It’s about multiple processes all doing their own thing. The multi-process approach is very popular on the Unix platform as well as Unix clones such as Linux. Again, it is a historical decision as much as a technical decision and its key considerations are:
  • Processes are managed by the operating system rather than by a master thread
  • Processes are self-containing, if all the other processes die, the one remaining continues to function unaffected
  • There is no shared memory to manage, although some information can be exchanged using a shared space

Now, what makes one better than the other? For me, it’s all about two competing desires: memory footprint and simplicity. Threads are a smaller memory footprint while multi-processes are simpler to implement. Interestingly, Google went the way of multi-processing and their reasons for doing it appear quite sound. I won’t go in to detail here but take a look at their comic presentation for details.

Focusing on the Tab

Google have also focused greatly on the tab. They think it so important, they put it at the top of the window. Each tab has its own address bar and buttons as well. What’s more, because each tab is a separate process, it’s simple to undock each tab in to a new window.

Speed

People I ask about Google Chrome all say the same thing: it’s fast. A lot of effort has been put in to speeding up the rendering engine as well as Google’s own JScript VM which compiles native code. It all makes a faster browsing experience.

Security

Google sandbox their browser processes. This means that websites can’t change your hosts file to some-very-bad-website.com to steal your credit card number or show inappropriate content. Of course, there are some limitations with plug-ins because they’re not sand-boxed, but the attach surface is greatly reduced.

Summary

So, why do I care about blogging about some new browser? The reason why is because it is another example of people getting together to produce a quality product. It’s not about what makes it so good, it’s about how Google went about creating this product. As a tester/developer, I want to make fantastic cool products that close the gap between people and their tasks.

Kind Regards
Glenn 





Stubs vs Mock Objects

15 09 2008

During my presentation on mock objects earlier this week, people started discussing the differences between stubs and mock objects. I wasn’t ready for this question and had used all my Q&A time up already. When I was asked to comment more on this off-line, I decided to discuss it a little here.

I’m not intending to write an essay here. Stubs and mock objects are quite interesting but I only want to give an introduction at this stage. So, with a quick refresher on the differences, here’s what I know…

Introducing a Term

To begin, I’ll need to explain what kind of objects both stubs and mock objects are. For this I’ll need to introduce a term. Since both stubs and mock objects are trying to achieve something similar, they can be grouped together. The phrase I’ve heard most is “Test Double”. The idea is that these objects are similar in some way to production code but aren’t completely identical. Instead, they are like stunt doubles in a movie. Martin Fowler tells us this term comes from Gerard Meszaros, who coined it in his book xUnit Test Patterns.

What is a Stub?

My understanding of stubs has been the same since before I learned about mock objects. The idea is of having a test double capable of satisfying the requirements of testing without the impact of some complex external system. When coded, these stubs normally provide information for consumption by the system under test.

Information within stubs are often hard-coded return values or properties. Their use is intended to satisfy the compilation requirements as well as fulfilling any needs required to test the intended behaviour of the system. The use of stubs is often confined to when production code either isn’t implemented yet or it would impact somehow to use a real object.

Here is a key concept when comparing with mock objects. Stubs are used generally when the real object either isn’t available or isn’t appropriate for testing. In most other situations, the real object is used.

Martin Fowler describes the purpose of stubs as being useful for state-based verification. Given that stubs normally have values and states hard coded, testing takes the approach of ensuring the system functions correctly in certain states.

What are Mock Objects?

I like to describe mock objects as simulations of an object. This description will likely be understood by some people and only work to generate more questions for others. Let me explain more…

Mock objects normally implement an object from end to end. They receive input, perform some process on that input, and generate output. The difference between this test double and a real object is that mock objects have an imaginary processing stage; i.e., it’s processes generate output based on what would happen if the real work had happened.

Let’s look at an example. Suppose I have an interface to determine what sizes a shoe manufacturer supplies as part of each model of shoe. The real object would take the name of the shoe and return all the sizes supplied. It might perform this operation by executing a stored procedure in a database to lookup the record ID of the shoe and match it against a many to many table relationship between shoe model IDs and sizes. It would then format the results in an array and return the results to the calling code.

A mock object would do exactly the same, it’s just that it would pretend that an array given as part of the unit test’s setup was the results of the database’s stored procedure. Let’s take a look at some code:

...
string sizes[] = {"8", "9 1/2", "11D"};
MockDatabase db = new MockDatabase(sizes);
string shoeName = "Puddle Jumper TM";
string shoeSizes[] = db.GetShoeSizes(shoeName);
...
Example 1: Populating a mock object with database information

As you can see, instead of going to a real database, it has some values we have chosen for our test case. Take note, this mock object may be used many times and could use a different set of shoe sizes for each test case. In fact, it could use several sets of shoe sizes within just one test case! This is an important difference from stubs, these values are not hard-coded.

In the background, GetShoeSizes(string) takes the given array and formats it in to the expected representation. On top of this, we could have added features for testing, such as counting the invocations of the method, generating exceptions, as well as ensuring these statistics are all within our expectations. Instead of a silent partner, the mock object becomes co-star, defining and testing our expectations!

Martin Fowler describes mock objects as being used for behaviour-based verification. The input and output are not coded but are instead in part processed (or as I term, an imaginary process), and defines the behaviour of the application.

This point is crucial. It beckons the introduction of contracts within the design of software. As soon as you have test cases defining the expected behaviour, as mock objects do, you are building a contract between the application, the test case, and the developer who is intending to develop the production code. For this reason, test cases should be written to reflect the requirements closely.

Summary

So, hopefully this blog post has helped with the question of what difference there is between stubs and mock objects. We’ve learned that stubs are normally hard-coded substitutes for production code whereas mock objects have an imaginary process which helps to build expectations of how the production system will behave. Also, we’ve learned that stubs work with state-based verification while mock objects work with behaviour-based verification.

Hopefully this has provided an interesting introduction to the area of mock objects. You can read more from Martin Fowler’s essay on this topic at http://martinfowler.com/articles/mocksArentStubs.html, where I did my quick refresh on the differences between these two kinds of objects.

This topic of stubs and mock objects moves in to the space of Design By Contract and Test Driven Design. See my post on Test Driven Design if you’d like my introduction to that space as well.

As usual, keep the discussion going and leave a comment.

Kind Regards
Glenn





Presentation

8 09 2008

Well, I did say I was going to be busy. Yes, I’m still here and Quality in Software is still active. Hooray!

These last weeks have seen me feeling like my time has been pretty thinly spread. Nevermind, still, what’s happening?

Well, tomorrow I’m giving a presentation on Testing Components with Complex Associations. It’s a dive in to the world of Mock Objects, patterns, and other things like that. Of course, I’ve held back because my space is only 20 minutes. Quality is such a big topic.

Just lately, I’ve been in a test lead role. It’s been good. I’m surprised just how much I think about my test lead back at Motorola; Chris Lawn. Very dedicated person who I believe has had an impact on how I approach the role of testing.

In the not too distant future? Work, I’m real busy right now, more blogging, and of course one of my favorite professional development activities, reading books. They’re so invaluable!

I’ve been meaning to have a page to share book titles. That will still go ahead. I look forward to sharing book titles with you all as I’m always on the lookout for a great book on quality.

Anyway, for now, it’s back to work. I just got an updated spec I have been waiting for so I’m on the quality trail yet again.

Kind Regards
Glenn





Throwing Away – Getting MVP Right

15 08 2008

It is part of programming folk law that we should throw away our first version of any software. Essentially, we are writing software that has never existed before and need to find the best approach. One problem I’ve always had with this is that not all of what we write is that bad on the first run. This may be because we’ve written something similar before or it’s so very simple that we can verify it works properly.

On the other hand, the technique of Refactoring promotes the evolution of software from a throw-away first edition to hardened quality. Refactoring is about improving what already works with each visit.

Yesterday, I realized I needed to choose Throwing Away. If you’ve been following my blog for the past week or so, you’ll know that I am writing a wedding application to track all the events related to my up-coming wedding next year. It uses the Model View Presenter (MVP) pattern as well as being architected via Test Driven Design.

Yesterday, I realized that I had written my Presenter to be the only Presenter in the entire application. This isn’t according to how the MVP works. It should be one presenter instance per view and a lot of the time, it’s a customized presenter built with a single task in mind: tasks such as adding a record, generating a report, etc. My Model suffered the same problem. My MVP had become closer to MVC (Model View Controller) and as a result, I had a monolith Presenter and Model.

Thinking about it deeply first, I decided to throw away my monolith Presenter and add another layer for the Model, abstracting it away from the business logic. I believe I have made the right choice.

If you want to learn more about MVP, there are some great resources. A new one I’m liking is http://www.codeproject.com/KB/architecture/DotNetMVPFramework_Part2.aspx.

Kind Regards
Glenn





MVP Pattern

12 08 2008

Hey!

I haven’t been blogging as much as I’d like to because I’ve been busy writing my Wedding Application. You can find more about it in my previous post but if you’d just like a quick synopsis, in my spare time, I’ve started writing an application around my coming wedding. Being busy with this is not all bad because it’s helped me to revisit a technology I learned about on-site. Let me tell you more…

If you don’t already know about design patterns, they’re essentially descriptions of what works most frequently in programming. They’re based on a lot of the work by Christopher Alexander with his architecture patterns. Now, before you go googling for “software architecture patterns by Christopher Alexander”, you might like to know his patterns are for buildings, suburbs, and other general living spaces: i.e., not software. Although Christopher Alexander’s work wasn’t designed for software, it’s inspired a generation.

Anyway, this post isn’t about all patterns, I don’t have that much spare time; it’s a very large topic. Instead, I want to talk about the pattern I’ve been using for the GUI of my wedding application. This particular pattern is called the MVP Pattern or Model View Presenter.

So, the whole idea behind this model is to decouple the UI controls from the UI logic and from the business model. It doesn’t do this by burying the UI logic with the business model, that would be a step in the wrong direction, but instead, it introduces a new layer. Let me explain more…

The MVP pattern is really about three parts. The first is the Model, the business model. This is where your business logic exists. It’s not unreasonable for the model to be a complete module containing all the non-UI stuff: business logic, persistence logic, etc, etc. It knows how to do stuff, like create records and apply business rules.

The next part of the MVP pattern is the View. This is what you get to see, literally. This is your forms and windows, your dialog boxes and your console screens. Now, what I need to mention here is that it is developed as an implementation of an interface. This is because it decouples so greatly, it allows you to swap and change your views: think of one application with one UI logic yet interchangeably displayed on Windows Forms, WPF, Console, ASP.NET, or Silverlight. The application isn’t changed, the IView (typically) interface is simply implemented differently.

Lastly, the MVP pattern introduces the Presenter. This is where your UI logic exists. It’s actually the driver for the UI and the main conduit between the view and the model. It’s responsible for updating data displays, formatting displays, and notifying the business model of user commands.

What I like most about the MVP pattern is that it makes your UI logic testable. Unlike UI drivers that send window messages to your application, MVP allows you to unit test your UI logic and that’s what I like about it. It’s really early in the development cycle, meaning less cost to fix any defects that are injected in the product at that stage.

You might like to look at more here. You will definitely want to know that Martin Fowler has decided to split the pattern in to two separate patterns called Supervising Presenter and Passive View. Definitely worth the read.

If you haven’t already, I really urge you to get in to design patterns. They really do help with software architecture and enough people know them that you can use them by name in conversation with other software engineers. If you’d like another great resource, try Do Factory, it doesn’t include MVP but it is good none the less and reflects the GoF (Gang of Four) design patterns.

Kind Regards
Glenn





Glenn’s Wedding App – Using Test Driven Design

6 08 2008

Here at DWS, I’m “On the Bench”. This essentially means I don’t have any client work to do so I’ve been doing things for DWS internally as well as professional development. With this spare time, I’ve been practicing my skills in XML, .NET 3.5, and TDD (Test Driven Design).

I’m not going to pretend that I know everything about TDD, I don’t. What I will do, however, is tell you about my understanding of this fast way of designing good quality software that has fantastic code coverage as well!

I used to code in .NET 2.0 a lot at home and in TAFE (a technical college where I learned software development): as well as .NET 3.0 as part of my job here at DWS. Having said that, much of my work for the last 9 months or so has been testing, specifically leading UAT at a client’s site, so my coding skills are a little rusty.

I wanted to sharpen these coding skills but first I needed a project. Too easy! My upcoming wedding to my darling fiancee Jenna is a great inspiration for a project! So, I started a project that tracks wedding-related events: you know those events, engagement party, pre-wedding parties, organising the wedding, etc. My project will tell me which events are coming up next as well as how much time there is until the event.

Now, where does Test Driven Design come in to this? Well, it’s a great way of getting software written quickly with high quality, so that’s the method I have chosen to write my program. So, what is Test Driven Design?

Test Driven Design as I understand it is a process where you begin with a single concept. This concept says that any piece of software may either be complete or incomplete. Any defects are just where the software is incomplete. To demonstrate this, a test is written that confirms the software is incomplete and provides a proof for when it is complete. It starts with writing a test case that describes a little of the functionality of the final product.

Once the test case is written, the test case is compiled. At this stage, there is no production code and so the compilation of the test case fails. Let’s take a look at an example:

[TestMethod]
public void DoStuffTest()
{
  Something target = new Something();
  bool expected = true;

  target.DoStuff();
  bool actual = target.StuffDone;

  Assert.AreEqual(expected, actual);
}
Example 1: Initial Test Case

So, there’s a test. The idea here is that Something doesn’t exist, so the compiler fails to compile the test. Let’s add Someting.

public class Something { }
Example 2: Inital Production Code

Ok, so I know what you’re thinking, “He’s left out all the boring stuff.” Not at all, that’s it! There isn’t anything more. Let’s compile… Compilation Failed! Error: DoStuff() is not defined.

That’s right, we have stubbed the class but haven’t filled in the methods yet. Simply put, we didn’t do that because it wasn’t necessary to fix the problem at hand. That’s what TDD is about, fixing what is at hand to the very minimum required to satisfy the tests. As a result, you get very high code coverage, as in greater than 90%, often 100%, and the code is simple and testable.

We continue down this path until we finally get a compiled program: Compilation Successful! Now we run the test…

Test Failed: Expected: true, Actual: false

What happened? Let’s look at the code.

public class Something
{
  public void DoSomething()
  { }

  public bool StuffDone
  {
    get { return false; }
  }
}
Example 3: Production Code - Meeting the minimum requirements of the test case

Ah, this is easy to fix:

...
get {return true;}
...

Now it passes! Fantastic! But now we have only proven that we can know when something has happened, what about before it’s happened? Let’s change our test:

[TestMethod]
public void DoStuffTest()
{
  Something target = new Something();
  bool expected1 = false;
  bool expected2 = true;

  bool actual = target.StuffDone;
  Assert.AreEqual(expected1, actual);

  target.DoStuff();
  actual = target.StuffDone;
  Assert.AreEqual(expected2, actual);
}

Example 4: Updating the Test Case

Now, see the change? We check target.StuffDone before we call DoStuff() and expect it to return false. Of course it should be false, we haven’t “done stuff” yet! Let’s compile: Compilation Successful. Not a problem, it only exercises existing production code. Let’s run the test:

Test Failed: Expected: false, Actual: true.

Ok, so what happened? Remember how we made our code work by statically returning true from the StuffDone property? We’re going to have to be a little smarter now.

How can we get the test to pass with the simplest change to the production code? Really, the best way is to change the result of StuffDone when we call DoStuff(). Because the first Assert statement expects StuffDone to be false, that’s what we’ll initialize it to satisfy that test.

// Something that does stuff.
public class Something
{
  private bool mStuffDone = false;

  // Do something.
  public void DoSomething()
  { mStuffDone = true; }

  // Has something been done? Return true if yes.
  public bool StuffDone
  {
    get { return mStuffDone; }
  }
}
Example 5: The Completed Production Code

Easy! Now, I know what you’re thinking, it’s easy because it’s just some simple example. Well, yes, that’s right but it’s also how TDD works. Everything is broken down in to simple bite-sized pieces. Now, think about what we have here. We have a fully tested piece of production code, a simple design, and a test that proves that we have delivered on the requirement described by the test case: let’s just say, green ticks are hard to argue with.

You’ll likely want to refactor your code at some stage but at least you won’t be refactoring too early and you have test cases to check that your refactoring doesn’t break anything. Try writing test cases around the requirements in your projects. I find it easy and rewarding.

Kind Regards
Glenn





Unfamiliar

28 07 2008

Hello again

I didn’t write all weekend or yesterday; Monday for those of you on the other side of the dateline. It’s not that I didn’t have thoughts of writing, it’s just that my thoughts didn’t become something I felt was good enough for this blog. Again, quality exists everywhere.

Anyway, today I want to talk about the milk in the fridge here at DWS. “Milk?” I hear you say; yes, milk.

Here at Quality in Software, anything can inspire a talk about quality, even milk. Anyway, enough of this ranting and on with today’s post…

Last week, I think it was on Thursday (5 days ago), a 1 litre carton of milk appeared in the upstairs fridge. What is odd about this is that we always have either a 2 litre or a 3 litre milk bottle. So what does it mean to software quality?

You see, no one has opened this poor carton of milk. It has been left there while bottles after it have been opened, emptied and replaced. So why has this poor carton of milk that sits faithfully in the fridge not been opened and used?

It reminds me of how people often don’t use great features in software. Often, great features in software can sit faithfully unused in our products while some common-place feature gets used again and again, even if it does mean more effort on the part of the person using the software. The question is why?

People are habitual beings. They tend towards the familiar and often avoid the unfamiliar. So does that mean this poor carton of milk in the fridge and the great features in software all go unused largely because they’re unfamiliar to their habitual human users? Yup! It does.

Now, I know not everyone is so habitual as this but I only comment on the results I see. And yes, I am one of these habitual users, which is why I can say that when I look at that poor carton of milk, I think, “Someone must have bought it for themselves and simply haven’t taken it home yet.”

One of two things will happen. Either people will continue to avoid the unfamiliar until the unopened milk goes bad and the great features of software get removed, or, just their constant “being there” will provoke a certain level of expectation, of familiarization. Either way, the milk won’t always be there: it will get consumed or thrown away. Now, while you’re thinking of how much of a waste this is while children go hungry in other lands, remember this is a software quality blog, not a human rights blog but I can understand your thoughts on this line.

Anyway, the idea from this is to be careful when adding fantastic features that will change the world. If they aren’t familiar to people or use basic principles that people already know, they will avoid it. It’s not because it’s bad or it doesn’t work, it’s just because it’s unfamiliar. When you do your designs and review quality, try considering the 1 litre carton of milk in the upstairs DWS fridge and present your feature in a way that is familiar to people.

Kind Regards
Glenn

p.s. no cartons of milk were wasted in the writing of this blog. :)