Showing posts with label MOCKS. Show all posts
Showing posts with label MOCKS. Show all posts

October 20, 2007

Software Development Essential Practices

I was in an interesting discussion last night: what software development practices do you consider essential? 

While opinions varied, I think there was some consensus on a few items.  In my list I also include some tools.  Some of these were mentioned by the group, but consider them my own additions.  Also, I am making this list specific to .NET, but the list applies to just about every language.

Universally agreed Practices

  • Source Control (1)
  • Local Development -- Every developer should have everything on their computer to run the system.  This includes all of the software and all of the source code.
  • Bug Tracking - nuf said.  There are to many tools available to list here.
  • TDD - Test Driven Development.  There was a little bit of back and forth, but the general consensus was that this should be done.
  • ORM - Object-Relational Mapping
    • NHibernate 
    • SubSonic - My person favorite
    • LINQ to SQL - not yet, but I feel this should be on the list.
    • LLBLGen ($) - Not free, but I've heard many good things about it.
    • More
  • Continuous Integration - Simple process that sits on a server and waits for things to get checked into your source control system.  When it sees something new, it gets all of the latest source code, compiles it, and runs all of the unit tests.  If there are any problems anywhere in that process it alerts the users (email, desktop icon, wave red flag, etc). (3)
  • One Step Build - it is unbelievably cool to be able to click one button and have your entire project compile, run all tests, and possibly create an install in one step.  Personally, I do like it, but with the current set of tools this is one of the hardest parts to setup.

Highly thought of but non-essential practices

I'm sure I have missed some tools in the list, but it is the practices that are more important anyway.  But if you put a comment about any tool that I missed I will add it to the list.

(1) Source Safe was notably not in the list.  While I don't like it either, it is better than nothing.  But if your team is greater than 5 people or you have multiple people working on the same project you really should look at one of the other products on the list.

(2) Not a unit testing library, but a Mock Object library.  Pick a unit testing libarary (NUnit, MBUnit, XUnit), then pick a mock object library (Rhino Mocks, TypeMock, NMock) to use with it.

(3) I really need to talk about continuous integration more.  But it is one of those things that leads you down a path.  First you add source control, then you start adhering to separation of concerns, then you start unit testing and mocking more, then you add continuous integration, and then one step builds are all part of the mix.  One best practice leads to another, but they don't make a bit of sense without some of the prior pieces.

(4) If you are a Code Rush person instead of a ReSharper person -- carry on, you are in good company.

($) The cost money - not just beer, but may have free version versions as well.

June 14, 2007

Fake Objects in RhinoMocks

It seems Ayende is keeping busy with Rhino Mocks (aside from blogging 5 times per day). He has now implemented Fake Objects (called a Stub in Rhino Mocks).

First to give some background, there is a difference between a Mocked object and a Fake object.
With Fake Objects, think of a simple class with only properties containing both getters and setters. You can set any property to a value, but the fake object really doesn't care what happens to it. If you set a property to a value, it returns that value until that value is set to something else. I am not sure, but I don't thing you can tell a Fake object function what to return. So if you need that, you should probably use the Mock Object -- read on.

With Mock Objects, they are much more complex beasts. You must warn the Mocked object for every call made to the object, and tell the Mocked Object what to return. One nice thing about Mocked Objects is that functions can be mocked.

Each object, Fake and Mock, has their place in a testing scheme, so it is important to know the difference. If you need simple returns with getters and setters, and don't care if something does or doesn't get called use a Fake Object. Otherwise use a Mock Object.

Anyway, if I have an interface that looks like this:

   1:  public interface IMyObject
   2:  {
   3:        public string MyProperty1 { get; set; }
   4:        public string MyProperty2 { get; set; }
   5:  }

I can create and use a Fake Object for it like this:
   1:  IMyObject o = MockRepository.GenerateStub<imyobject>();
   2:  o.MyProperty1 = "Hi";
   3:  o.MyProperty2 = "There";   
   4:  Assert.AreEqual("Hi", o.MyProperty1);
   5:  Assert.AreEqual("There", o.MyProperty2);
as apposed to creating and using a Mock Object
   1:  MockRepository mock = new MockRepository();
   2:  IMyObject o =  mock.CreateMock<IMyObject>();
   3:  Expect.Call(o.MyProperty1).Return("Hi");
   4:  Expect.Call(o.MyProperty2).Return("There");
   5:  mock.ReplayAll();
   6:  Assert.AreEqual("Hi", o.MyProperty1);
   7:  Assert.AreEqual("There", o.MyProperty1);
   8:  mock.VerifyAll();
As you can see, there is nothing special to using a Fake Object, just set and get the properties like normal. Whereas with Mock Object you have to call Expect.Call for everything that gets touched.

Have fun.

January 23, 2007

Adventures in Agile Development

I've started a new project, with a new team, under a new development methodology. And for the most part I am happy with that. We have a small team of two developers and an architect/manager/used to be coder, and we are going as agile as possible.

Now Agile development means a lot of different things to a lot of different people. It is so bad that saying that you are an agile shop can mean almost anything you want it to. So to alleviate some of the confusion, here is some of what we are doing.
  1. Daily Scrum. This is a 10-15 minute meeting every morning to talk about what is going on with your code. Where are we at, what are we trying to do.
  2. Test Driven development. This means having tests for as much as possible (NUnit in our case). Granted, you cannot test everything, but there are development patterns that allow you to test most of what you do. Chief among them is the MVP pattern (Model-View-Presenter). I'll talk more about this later.
  3. Frequent check-ins. It goes like this. Write a test for your code. Write the code. Make sure the test works. Check in. This means you are checking in up to four times per day. It also means you are less likely to get lost in all the things you are trying to do. And it means you need a source control system (we are using Subversion), and an automated build process (we are using NANT and Cruise Control).
  4. The customer is allowed to get the daily build. This way they can keep up to date with what you are doing.
  5. Now throw in an alphabet soup of other best-practice-somewhere technologies like Rhino Mocks, Spring, and NHibernate . You see there is a lot to learn.
Luckily, Agile and Test driven development have reached a critical mass such that there are now tools to help you with this process. I've already mentioned NUnit, NAnt, Subversion, and Cruise Control. But there is also the excellent Microsoft Team Systems that has all of those tools bundled together.

Another tool that wasn't listed that we are also using is ReSharper. Very cool tool with a lot of enhancements to Visual Studio.NET -- and a little bit of pain as well. ReSharper has an extremely large collection of shortcuts, so many that it actually overwrites a number of Visual Studio.NET shortcuts. But, it does have a feature to deal with that. Any time you his a shortcut that both ReSharper and Visual Studio.NET want, a dialog pops up asking which short-cut to use. I guess that is the best compromise. Anyway, for the side of ReSharper, the refactorings, and unit test integrations make it worth the cost of entry (a little over $100).

Now, this is enough for right now. I hate overly long rambling blog posts, and I'm afraid this will have to turn into a series. So, next time I'll write up what MVP, Spring, NUnit, and Rhino Mocks have to do with each other.