Development Blog

 Thursday, January 10, 2008

stack-bar-chart

With Mingle 1.1 came several great new features, including date fields. Now you can track the date that you complete tickets by adding a Date Done field (along with a Complete transition that sets the Date Done field to today) and locking the Status field to be editable only by transition.

This works great for newly completed cards, but what about all the cards you already have in your system? Sure you could go without burn-up charts and date stats for those cards, but what's the fun in that? 


taskcomplete

Fortunately, Mingle tracks every card change in a history table. Each change in the history table has a date associated with it, so all we need to do is figure out how to extract the dates we care about. I must warn you, this is a little complicated, and I'm sure ThoughtWorks doesn't at all condone you mucking around in your Mingle database manually, so please please back up your database before attempting this and of course I'm not responsible for any damage you do. That said, here's how I was able to retroactively add dates for our two date fields: Date Done, and Date Published.

  1. Back up your Mingle DB. Really.
  2. You'll need to identify the field you use to track status. We use Status. We have Status of 'Not Done', 'Done', and 'Published'.
  3. Then connect to your Mingle database and find the name of your cards table and your card_versions table. Our project is called "eleutian_speakeng" so our tables are "eleutian_speakeng_cards" and "eleutian_speakeng_card_versions".
  4. Add the date fields you want to populate if you don't already have them. We have "Date Added", "Date Published" and "Date Done".
  5. Figure out which fields in the two tables you identified map to your status and dates (this is usually as easy as prepending cp_ and box_caring your names. For us we have cp_status, cp_date_published, cp_date_done, cp_date_added.
  6. Edit the following queries to add in your table/field names and values (these are the exact queries I ran, you'll need to change the red things):
    UPDATE eleutian_speakeng_cards SET cp_date_added = created_at
    
    UPDATE eleutian_speakeng_cards card SET card.cp_date_done = (
      SELECT MAX(b.updated_at) 
        FROM eleutian_speakeng_card_versions a
      INNER JOIN eleutian_speakeng_card_versions b ON a.number = b.number 
        AND b.version=a.version+1 
      WHERE card.number = a.number
      AND (a.cp_status='Not Done' OR a.cp_status IS NULL) AND b.cp_status='Done'
    ) WHERE card.cp_status = 'Done'
    
    
    UPDATE eleutian_speakeng_cards card SET card.cp_date_published = (
      SELECT MAX(b.updated_at) 
        FROM eleutian_speakeng_card_versions a
      INNER JOIN eleutian_speakeng_card_versions b ON a.number = b.number 
        AND b.version=a.version+1 
      WHERE card.number = a.number
        AND (a.cp_status IN ('Done', 'Not Done') OR a.cp_status IS NULL) 
        AND b.cp_status='Published'
    ) WHERE card.cp_status = 'Published'
    
  7. Once you've got that taken care of, go ahead and run the queries (you backed up right?) and you should be good to go.

So now that you've got your dates in your database, how do you get the cool burn up chart? Like this (mold to your project):

{{
   stack-bar-chart
   x-label-start: SELECT MIN('Date Added')
   x-label-end: Today
   x-label-step: 14
   chart-height: 600
   chart-width: 700
   plot-height: 500
   plot-width: 550
   conditions: Type IN (Bug, Story, Task)
   three-d: true
   cumulative: true
   series:
     - label: 'Not Done'
       color: #e6a800
       data: SELECT 'Date Added', COUNT(*)
       type: area
     - label: Done
       color: #1bcc00
       type: area
       data: SELECT 'Date Done', Count(*) WHERE 'Date Done' IS NOT NULL
     - label: Published
       color: #0079bf
       type: area
       data: SELECT 'Date Published', COUNT(*) WHERE 'Date Published' IS NOT NULL
}}
agile | development | mingle | tips | tools
by Aaron on Thursday, January 10, 2008 11:48:38 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, September 10, 2007
mount19

OK, so it's not 100% free as you'll need a few drywall anchors (if you're not on a stud) and screws, but you probably have those laying around, and other than that it's free. When you're done, you'll be able to move the monitor up and down, tilt it up and down, and rotate it, just like you can on its stand.

I started taking it apart to see what I could do with it and I didn't start taking pictures until I was almost done, so you're going to have to use your imagination a bit on some of the pics and some of the steps may be off a bit. It looks like a lot of steps, but they're tiny and somewhat detailed... all in all it's pretty easy. Any ways, here you go:

  1. Pull off the monitor from the stand by pushing the black button and rotating it off.
    mount1
  2. Unscrew the four screws that mount the connecting plate to the stand and pull the connecting plate off.
    mount2
  3. This may be optional, but it's easy: unscrew the two little screws on the gray plastic circle and pull it off.
    mount3
  4. This is also probably optional: unscrew the two screws holding the plastic hinge cover on and pull off the cover.
  5. Pull off the bottom black plastic piece from the track on the stand.
    mount5
  6. Use all of your might to push the mount down to the bottom of the track until it locks.
  7. Pull off the rest of the black track cover (this is a little tricky, and I broke some of the tabs doing it, but who cares, right?) Basically you have to pull the sides out from each other and go all the way up to the top, then slide the middle part out.
  8. Push the button so that the mount slides (very quickly, watch your hands) to the top.
  9. Unscrew the three screws holding the long metal piece down to the track assembly and pull it out. Things will fall out, don't worry that's fine.
    mount9
  10. Unscrew the four tiny screws holding the track assembly to the stand. These screws were a pain because they're in there pretty tight and they're so small. I stripped one of them and had to drill it out.
  11. Unscrew the four screws holding the rear bracket to the two track rails.
    mount11
  12. Rotate the rails up and pop the metal coil out of the plastic thing.
    mount12
  13. Mount the rear bracket using the incredibly convenient four screw holes to the wall. I used some 2"x1/4" plastic drywall anchors and 1.5" screws. If you have a stud there, all the better, but it may be tricky getting all 4 screws into the stud.
    mount13
  14. Pop the metal coil into the plastic thing at the top of the bracket. Check to make sure it got in there straight or you may have some annoying problems.
    mount14
  15. Replace the four screws to secure the tracks to the bracket. In order to do this I needed to hold the mount a few inches down from the top and have my girlfriend screw the screws into the rails. That last sentence may get me some unexpected traffic from google.
    mount11
  16. Purely optional: Replace the two plastic covers and the four screws.
  17. Replace the mounting plate and secure it with all four screws.
  18. Play with the plate/mounting a bit to make sure its secure before putting the monitor on it.
  19. Put the monitor onto the mounting plate.
    mount19 mount20
  20. Hook up your cables and enjoy--if you're feeling adventurous, feel free to drill some holes and fish those cables through the wall :)
diy | hardware | tips
by Aaron on Monday, September 10, 2007 6:38:28 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, August 05, 2007

Jacob posted about the AutoMockingContainer several months ago. At that time we didn't really use it, it was just kind of an implementation of an idea. Well, we've finally started using it in some side projects (Resharper.TestDrive for example), and I must say... wow. It is most definitely the way to instantiate your subject under test most of the time. Why?

  1. It decouples your tests from your constructors. This means that if you have multiple TestFixtures for a class and you want to add a new service to your constructor, you don't have to change a thing in your tests.
  2. It simplifies your tests. Things are just cleaner when you're not having to create all your mock services to inject into your subject under test.
  3. It helps reinforce good mock usage. The default mock strategy is dynamic mocks. You can override that if you want to, but most tests should (in my opinion) be written with dynamic mocks. Like Dave talks about you only really want to set actual expectations on zero or one mock at a time. Everything else should be more stub-like.

I've started to use a base class for all my tests. Let's take a look at ReSharper.TestDrive's test base class:

  public abstract class AutoMockingTests 
  {
    private MockRepository _mocks;
    private AutoMockingContainer _container;

    protected MockRepository Mocks
    {
      get { return _mocks; }
    }

    protected AutoMockingContainer Container
    {
      get { return _container; }
    }

    [SetUp]
    public void BaseSetup()
    {
      _mocks = new MockRepository();
      _container = new AutoMockingContainer(_mocks);
      _container.Initialize();
      Setup();
    }

    public abstract void Setup();

    public T Create<T>()
    {
      return _container.Create<T>();
    }

    public T Mock<T>() where T : class
    {
      return _container.Get<T>();
    }

    public void Provide<TService, TImplementation>()
    {
      _container.AddComponent(typeof(TImplementation).FullName, typeof(TService), typeof(TImplementation));
    }

    public void Provide<TService>(object instance)
    {
      _container.Kernel.AddComponentInstance(instance.GetType().FullName, typeof(TService), instance);
    }
  }

So what's a test look like with this base class? Let's borrow Dave's example.

  public class SearchPresenterTests : AutoMockingTests
  {
    private SearchPresenter _presenter;
    private SearchResultDTO _fakeResults;

    public override void Setup()
    {
      this._fakeResults = new SearchResultDTO();
      this._presenter = Create<SearchPresenter>();
    }

    [Test]
    public void Can_search_for_customers_by_number_of_orders()
    {
      using (_mocks.Record())
      {
        Expect
         .Call(Mock<ISearchService>().GetCustomersByOrderCount(42))
         .Return(this._fakeResults);
      }

      using (_mocks.Playback())
      {
        _presenter.SearchByOrderCount(42);
      }
    }

    [Test]
    public void Search_results_are_displayed_to_the_user()
    {
      using (_mocks.Record())
      {
        mockView.SearchResults = _fakeResults;
        SetupResult
         .For(Mock<ISearchService>().GetCustomersByOrderCount(42))
         .Return(_fakeResults);
      }

      using (_mocks.Playback())
      {
        presenter.SearchByOrderCount(42);
      }
    }
  }

Not bad eh? You can do some more complicated things too. Let's say all your presenters take a hub service called PresenterServices. Rather than mocking it and its child services and setting up expectations for each of the children you can just use the real one and do this:

      Provide<IPresenterService>(Create<PresenterService>());
      this._presenter = Create<SearchPresenter>();

Now you can refer to all your hub's child services with the Mock<T>() method.

Ok, so if you made it this far you probably want to check it out for yourself. Thanks to Ayende, the AMC it is now part of Rhino.Tools so you can check it out (svn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk rhino-tools)  and build it yourself or just grab the current trunk build with all the dependencies here. Hope Oren doesn't mind me building and linking this... ;)

by Aaron on Sunday, August 05, 2007 11:47:22 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [7]  |  Trackback
 Tuesday, June 26, 2007

Generally when I'm testing something that has dependencies my test fixture looks something like this:

  [TestFixture]
  public class FooTests
  {
    private MockRepository _mocks;
    private Foo _foo;
    private IBar _bar;

    [SetUp]
    public void Setup()
    {
      _mocks = new MockRepository();
      _bar = _mocks.DynamicMock<IBar>();
      _foo = new Foo(_bar);
    }

    [Test]
    public void Test()
    {
      using (_mocks.Unordered())
      {
        SetupResult.For(_bar.ProvideService()).Returns(1);
      }
      _mocks.ReplayAll();

      Assert.IsTrue(_foo.DoSomething());
      _mocks.VerifyAll();
    }
  }

Granted, I'm starting to use our AutoMocking Container more and more, but that's not the point of this post. As an aside, Ayende has some more examples on its usage and has added it to Rhino.Tools.

Anyways, back to the subject at hand. The above works great if nothing really happens in your Foo constructor. But what happens if part of the constructor is to call a method on IBar? Well surely you could just move the construction to the Test method:

    [Test]
    public void Test()
    {
      using (_mocks.Unordered())
      {
        _bar.DoSomeSetup();
        SetupResult.For(_bar.ProvideService()).Returns(1);
      }
      _mocks.ReplayAll();
      _foo = new FooTests(_bar);

      Assert.IsTrue(_foo.DoSomething());
      _mocks.VerifyAll();
    }

That works, but what if you have more than one test? Well, you could just do the same thing in every test, but that's an annoying amount of repeated code that doesn't add any value. You can't simply Extract Method on it because you'll most likely need to setup other expectations for other scenarios you're testing. So... now I do this:

    [Test]
    public void Test()
    {
      SetupMocks(delegate()
      {
        SetupResult.For(_bar.ProvideService()).Returns(1);
      });

      Assert.IsTrue(_foo.DoSomething());
      _mocks.VerifyAll();
    }

    public void SetupMocks(Block block)
    {
      using (_mocks.Unordered())
      {
        _bar.DoSomeSetup();
        if (block != null) block();
      }
      _mocks.ReplayAll();
      _foo = new FooTests(_bar);
      
    }

And this:

public delegate void Block();

Funny what a little Ruby exposure will do to you...

by Aaron on Tuesday, June 26, 2007 7:36:55 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Thursday, February 15, 2007
workspace Hosted on Zooomr

1 3007WFP + 2 2007FP = 4960x1600

Need I say more?

by Aaron on Thursday, February 15, 2007 11:14:50 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Sunday, February 11, 2007

It amazes me how often developers lack fundamental competencies. Things that every developer should at LEAST know about, somewhat understand and know the capabilities of (i.e. when they're presented with a problem that is easily solvable using something such as... oh, regular expressions, they can at least google the steps to a solution.) What I'm trying to say is:

Understand and make use of regular expressions whenever it is appropriate.

Unfortunately, if you're reading this blog, you probably read several other blogs, so you've already been exposed to regex's. If that's the case, the tip for you is:

Think of more ways you can use regular expressions, understand them even more, oh and tell a friend/coworker who doesn't subscribe to 30 dev blogs and doesn't understand/make use of regular expressions about them.

There are several resources for regular expressions.

Roy Osherove has come up with some pretty killer tools for regex:

What do you do with them? Well, there are tons of uses for them, but here's a quick list of some of the basic things they're used for:

  • Find things - Duh.
  • Replace things - tons of cool stuff you can do here with and without capture groups. Here's a naive example:
    Foo bar
    Blah yadda
    Etc etc
    // search: (\w*) (\w*) replace: \1 \2 = new \1();
    // becomes:
    Foo bar = new Foo();
    Blah yadda = new Blah();
    Etc etc = new Etc();
    
  • Parse things - obviously we love to parse things.
by Aaron on Sunday, February 11, 2007 10:33:10 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, February 09, 2007

I've seen several people say the following when talking about TestDriven.NET: "It's so easy, just right click, and click run tests!" Maybe I'm just too lazy, but what's easy about moving my hand to the mouse, right clicking, finding the appropriate menu item and clicking it?

Bind a key to Run Test(s) and Run Test(s) with Debugger (I use Ctrl+Shift+R and Ctrl+Shift+D)

Just look for TestDriven.NET.RunTests and TestDriven.NET.Debugger in your keyboard settings. I personally use Resharper's Unit Testing feature (except in our 32bit apps on our x64 machines... they're still fixing that bug), but it's all the same. Bind a key to it. Real easy to finish up a test, hit Ctrl+Shift+R, and away you go. No arm movement required!

by Aaron on Friday, February 09, 2007 4:46:23 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Tuesday, February 06, 2007

This goes hand in hand with the first tip, so I figured I should post it now.

Get Gaston Milano's Cool Commands 4.0 and bind a key to Collapse All Projects (I use Ctrl+Alt+C)

There are plenty of other useful gems in CoolCommands (e.g. copy/paste project reference is very useful), but the one I use several times a day is Collapse All Projects. If you've got 40 projects, collapsing them all makes selecting the 36 projects you want to unload much easier.

by Aaron on Tuesday, February 06, 2007 8:45:14 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [2]  |  Trackback

I don't like waiting for things. I don't like typing the same thing over and over again for days, weeks or even months on end. I do as much as I can to speed my production of code up. I want the bottleneck to be in my mind, not in my fingers or my cpu. I figured I'd share some of the things I've learned along the way. Hopefully, a few of the tips will grab your interest and make coding just a little bit less tedious for you. So without further blathering, onto the first tip.

Bind keys to Unload Project and Reload Project (I use Ctrl+Alt+U and Ctrl+Alt+R) and liberally unload projects you aren't mucking with.

This may not apply to you, but here at Eleutian we have about 40 projects to build. Client, server, tools, shared libraries, generators, preprocessors, etc and of course tests for all of them. If you have all 40 projects open, just the dirty check during a build can take up a good amount of time. Generally you're only working on a few projects at a time, so go ahead and unload the rest (you can shift and ctrl select multiple projects to unload or reload). Every build you do (if you're doing TDD, you're dong several) will take significantly less time. Less time between build/test runs is a huge win. Adding the keybinding just saves you from fishing through the 100 item project context menu.

by Aaron on Tuesday, February 06, 2007 8:36:42 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [1]  |  Trackback