Attending, Innotech, a local Austin conference – level 000

This Wednesday, I attended the Innotech conference (no relation to Office Space), where I attended a session given by Mary Poppendieck, the author of Lean Software Development.  She elaborated on some principal of making software development more lean.  It starts with eliminating waste.  At lunch, we convinced her to come out to a local burger place and had a great time discussing software and Agile over burgers.  Coincidentally, every attendee is a member of the AgileATX practitioners group.  Pictured, you’ll see Jeffrey Palermo (me), Blake Caraway, Steve Donie, Scott Bellware, Bret Pettichord, Phred Menyhert, Jeremy Miller, and Mary Poppendieck.

How to set up a productive working environment for Agile teams – level 200

In Agile Software Development, there is a strong focus on collaboration.  Sending emails back and forth just doesn’t cut it, and weekly meetings are enough.  Offices and cubicles can often stifle communication because there are physical barriers in the way of communication. 


My team works in a single conference room with tables grouped together in the center.  Each person has a table as a desk, but all the tables touch and form a large rectangle (all the wires go in the middle).  When a conversation is going on, even non-participants can hear, and often a non-participant can correct a misconception or challenge an assumption.  Having everyone physically together all the time helps keep momentum going.  We have 96 sq feet of white board space, but we are getting some more so that every wall is covered in whiteboard – 288 sq ft. 


Having everyone together also aids in pairing because pairing can be initiated at any time with great ease.  We use VNC for pairing, and that allows us to remain comfortable with a dedicated keyboard, mouse, and display.  The alternative would be rigging two of each to a single computer, and the setup and teardown of this configuration takes time.  Using VNC, we can share a workstation instantly. 


Meetings should be able to be initiated at any time.  Don’t wait for a conference room to become available.  Any time any member is waiting on something, it’s a blocking scenario.  If someone is blocked, their time is being wasted, and the company is ultimately loosing money – work is hindered – productivity minimized.  Finding a meeting room is a blocker.  My team works _in_ a meeting room, so when we need to talk, we talk.  If we need to do some modeling, we just start drawing on the whiteboard.


Many organizations have environments that directly kill productivity.  If you have to schedule meetings in advance. . . if you ever find a whiteboard moment and have to search for a marker. . . you are wasting productivity.  Most of the time, management thinks that more meeting space and ample office supplies would cost unnecessary money, but they forget that their biggest business expense is payroll.


The IT infrastructure of the company can also be a blocker, and management is usually the only entity that has the authority to correct this:  there is often politics involved.  Organizations where server admins are shared among project teams are just asking for trouble.  Invariably, the server admin is always working “on the other guy’s project”.  A software product team can achieve maximum velocity while server resources aren’t adequate.  Other IT policies can get in the way as well:  If every interesting website on the Internet is blocked by a proxy, a valuable development resource is likely to be blocked as well.  Did you know that some software shops have _newgroups_ blocked! 


Continue reading about this topic with an essay from AgileModeling.com on “Organizing an Agile Modeling Room

How to use NMock to assist with unit testing – level 300

When you unit test, it is important to mock dependencies.  You can use static mocks (which are really just dummy classes that implement your interface) or dynamic mocks which can save code some of the time.  NMock is one of the frameworks for dynamic mocks.  They work by creating a class instance at runtime to match your specifications.  You take the instance of this class and use it like any other object.  Below are several scenarios for using NMock to create runtime instances of an interface.  This also works for abstract classes and concrete classes with virtual members.


    1 using System;


    2 using System.Security.Principal;


    3 using NUnit.Framework;


    4 using NMock;


    5 


    6 [TestFixture]


    7 public class NMockDemo


    8 {


    9     [Test, ExpectedException(typeof(VerifyException))]


   10     public void FailsBecauseWrongThingWasPassedIn()


   11     {


   12         IMock mock = new DynamicMock(typeof(IPrincipal));


   13         mock.ExpectAndReturn(“IsInRole”, true, “AdminRole”);


   14 


   15         IPrincipal principal = (IPrincipal) mock.MockInstance;


   16         bool result = principal.IsInRole(“TechRole”);


   17 


   18         mock.Verify();


   19     }


   20 


   21     [Test, ExpectedException(typeof(VerifyException))]


   22     public void FailsBecauseMethodWasntCalled()


   23     {


   24         IMock mock = new DynamicMock(typeof(IPrincipal));


   25         mock.ExpectAndReturn(“IsInRole”, true, “AdminRole”);


   26 


   27         IPrincipal principal = (IPrincipal) mock.MockInstance;


   28 


   29         mock.Verify();


   30     }


   31 


   32     [Test]


   33     public void Suceeds()


   34     {


   35         IMock mock = new DynamicMock(typeof(IPrincipal));


   36         mock.ExpectAndReturn(“IsInRole”, true, “AdminRole”);


   37 


   38         IPrincipal principal = (IPrincipal) mock.MockInstance;


   39         bool result = principal.IsInRole(“AdminRole”);


   40 


   41         mock.Verify();


   42     }


   43 


   44     [Test]


   45     public void SetupResultThatCanBeCalledManyTimes()


   46     {


   47         IMock mock = new DynamicMock(typeof(IPrincipal));


   48         mock.SetupResult(“IsInRole”, true, typeof(string));


   49 


   50         IPrincipal principal = (IPrincipal) mock.MockInstance;


   51 


   52         mock.Verify();


   53     }


   54 


   55     [Test]


   56     public void HowToSetupMockPropertyWithNestedMock()


   57     {


   58         IMock mock = new DynamicMock(typeof(IPrincipal));


   59         mock.SetupResult(“IsInRole”, true, typeof(string));


   60 


   61         DynamicMock identityMock = new DynamicMock(typeof(IIdentity));


   62         identityMock.SetupResult(“Name”, “someUserName”);


   63         mock.SetupResult(“Identity”, identityMock.MockInstance);


   64 


   65         IPrincipal principal = (IPrincipal) mock.MockInstance;


   66         Console.WriteLine(principal.Identity.Name);


   67 


   68         mock.Verify();


   69     }


   70 }


How to use SQL Server Express (where’s the UI?) – level 200

If you are used to working with SQL Server 2000, you may expect to find a tool similar to Enterprise Manager and Query Analyzer.  SQL Express is a free product, and it shows, but you get an awful lot for free. . . but you don’t get it all.  I think that’s perfectly fine.  I’d rather have something for free than nothing.


Here’s a few tips to get you started:



  • SQL Express installs as a local instance named “SQLEXPRESS”, so your connection string needs to include the instance name:  “.SQLEXPRESS” or “localhostSQLEXPRESS”.
  • SQL Server Configuration Manager isn’t the UI you want to add databases, tables, etc.
  • Use any of the Visual Studio Express products as your database UI.  They all have the database manager built in.

    • Use the Server Explorer window to add your database instance.  Then you can use it to add a new database and add tables to that database. 
    • If you have database create scripts, you can run them inside Visual Studio Express.  If you are used to hitting F5 in Query Analyzer, then you’ll want to map a shortcut key to the “Run Selection” command: Right click -> Run Selection.
    • You can create all your database objects here.
    • You can run and step through stored procedures for debugging.

  • You can also use osql.exe to manager your database.  This is useful when you want to automate database scripts using NAnt.
  • You have the option of how you want to connect to a SQL Express database:

    • Through the SqlClient provider: Data Source=localhostsqlexpress;Initial Catalog=MyNewTestDatabase;Integrated Security=True;Pooling=False
    • Through a file reference: Data Source=.SQLEXPRESS;AttachDbFilename=C:opensvndevelopmentezwebtrunksrcwebsiteApp_DataASPNETDB.MDF;Integrated Security=True;User Instance=True
    • If using ASP.NET, you already have a connection string you can use: LocalSqlServer:  Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;User Instance=True

See http://www.aspfaq.com/sql2005/show.asp?id=3 for more information.  There are other, non-Microsoft, tools that can be used to manager SQL Express as well.


UPDATE:  There is a November 2005 CTP of SQL Server 2005 Express Management Studio available.  This version is being linked to right off the SQL Server express download page.

Get Visual Studio 2005 and SQL Server 2005 for free at a launch event – level 000

That’s right.  Attend a launch event, and you’ll get the standard
version of that software for free.  That’s very valuable if your
company doesn’t provide copies for your personal use.  SQL Server
standard is plenty capable for most database requirements as
well.  These are full versions, not Express version. 

The Austin MSDN Event launch is sold out, but the Houston event on Dec
6th is still accepting registration, so go reserve your spot now.

GotDotNet.com is DOWN. Has been down all day – level 000

I’m almost completely fed up with GotDotNet.  I’ve been using them
to host my EZWeb workspace:
http://www.gotdotnet.com/workspaces/workspace.aspx?id=949a0c93-38f2-4bd2-9f69-a49bb3c7938d

I’m sorry you can’t get to the download right now.  I’m going to
have to pull my workspace and host it myself.  I need something
reliable.  They have been down all day, and when the site _is_ up,
it’s very slow.

Simple dependency injection to get you started with unit testing – level 200

More and more people are talking about unit testing, and I’m glad.  There is confusion, however, with unit testing and integration testing, and some folks don’t know there is a difference.  Unit testing is testing code in isolation without exercising code not under test.  Simply put, if I have a class that handles data that is stored in a file, I want to test my custom class without actually exercising the file system.  How do I do that?  Why do I want to do that.  I’ll tackle the why first.  If a test requires that an actual file exists, then you have a pretty significant dependency in your code.  Your code can never run (can never be tested) except by working with the actual file on a file system configured with the correct permissions.  This is fraught with environmental headaches.  Unit tests should be simple and fast.  The unit tests should pass everywhere, not just on one magic environment where everything is painstakingly set up.

Here’s how:  Consider the following code with a test:


    1 using NUnit.Framework;


    2 


    3 namespace DIPSample


    4 {


    5     [TestFixture]


    6     public class DataManagerTester


    7     {


    8         [Test]


    9         public void SaveDate()


   10         {


   11             DataManager manager = new DataManager();


   12             manager.AddData(“Some string data”);


   13             manager.SaveData();


   14         }


   15     }


   16 }




    1 using System;


    2 using System.IO;


    3 


    4 namespace DIPSample


    5 {


    6     class DataManager


    7     {


    8         private string _data;


    9 


   10         public void AddData(string data)


   11         {


   12             _data = data;


   13         }


   14 


   15         public void SaveData()


   16         {


   17             string path = @”C:dataFile.dat”;


   18             if(!File.Exists(path))


   19                 throw new InvalidOperationException(“Data storage isn’t ready.”);


   20 


   21             //Do something to maintain this data file. . .


   22             //Add info to file, replace data in file, etc.  Use your imagination.


   23         }


   24     }


   25 }


This test seeks to verify that SaveData() does what is is supposed to do.  The problem is that if our file isn’t available the code will fail.  I’m not in a position to configure the environment so that the file is available.  I don’t want to mess with the actual file at this point either.  I’ll need to modify the code so that it’s testable by itself.  The following is the same code modified to be more flexible so that the unit test _is actually a unit test_.  The above test is actually an integration test because its running requires the file system to be on the testing stack.

I define an interface to separate my file system dependency:


    1 namespace DIPSample


    2 {


    3     public interface IDataFileStore


    4     {


    5         void SaveData(string data);


    6     }


    7 }


I make my concrete implementation that calls the file system.  This will be my class for integration and acceptance tests.


    1 using System;


    2 using System.IO;


    3 


    4 namespace DIPSample


    5 {


    6     public class FileStore : IDataFileStore


    7     {


    8         public void SaveData(string data)


    9         {


   10             string path = @”C:dataFile.dat”;


   11             if(!File.Exists(path))


   12                 throw new InvalidOperationException(“Data storage isn’t ready.”);


   13 


   14             //Do something to maintain this data file. . .


   15             //Add info to file, replace data in file, etc.  Use your imagination.


   16         }


   17     }


   18 }


Here is how my DataManager class changes.  Notice the default constructor and a special constructor specifically for testing:


    1 namespace DIPSample


    2 {


    3     class DataManager


    4     {


    5         private string _data;


    6         private IDataFileStore _fileStore;


    7 


    8         public DataManager()


    9         {


   10             _fileStore = new FileStore();


   11         }


   12 


   13         public DataManager(IDataFileStore _store)


   14         {


   15             _fileStore = _store;


   16         }


   17 


   18         public void AddData(string data)


   19         {


   20             _data = data;


   21         }


   22 


   23         public void SaveData()


   24         {


   25             _fileStore.SaveData(_data);


   26         }


   27     }


   28 }


And in my test below, I use NMock to mock the interface.  It also allows me to verify that the proper method is called with the right data on my interface:


    1 using NUnit.Framework;


    2 using NMock;


    3 


    4 namespace DIPSample


    5 {


    6     [TestFixture]


    7     public class DataManagerTester


    8     {


    9         [Test]


   10         public void SaveDate()


   11         {


   12             IMock mock = new DynamicMock(typeof(IDataFileStore));


   13             mock.Expect(“SaveData”, “Some string data”);


   14 


   15             DataManager manager = new DataManager((IDataFileStore)mock.MockInstance);


   16             manager.AddData(“Some string data”);


   17             manager.SaveData();


   18 


   19             //Verifies SaveData method in the mock is actually called with the right input.


   20             mock.Verify();


   21         }


   22     }


   23 }


This is called Dependency Injection.  You are injecting a dependency to facilitate unit testing.  This decouples your code, and it is now more flexible.  The above is very important because if you can’t do this, then it will be VERY difficult, nay, impossible to do unit testing on a system that uses: files, a database, queues, web services, remoting, {shudder} DCOM, ASP.NET.