Thursday 2 July 2009

Pre-tested commit in TeamCity

I've been meaning for a while to have a look at pre-tested commit functionality in TeamCity* and today I got a chance to try it out.

It's a pretty simple idea. When you are ready to commit your changes to source control, you have TeamCity check that your commit is not going to break the build. Having someone else on your team commit bugs, failing tests, or, even worse, compilation problems to the repository is a serious time waster. A problem committed is a problem doubled...

So how is this different from just checking it yourself by compiling locally, running tests and committing? Well, there are several advantages from getting TC to do it.

Firstly, TC runs the checks remotely. It takes all the code you were going to commit, sends it to the build grid, and runs your tests there. If the tests fail, the changes are not committed, and no-one else has to suffer! Already this week I have broken the build a couple of times by accidently only committing only some subdirectories of changes (I use Subversion for source control and TortoiseSVN as my client tool). This is avoided as TC bundles all your working copy changes up for you so you don't forget to commit some code.

Secondly, TC runs the checks remotely. Yes I am repeating myself! Once you have asked TC to pre-test commit, you can continue making changes while the CPU intense stuff happens on another box. The local changes which you make after the pre-test commit do not interfere with the pre-test and you can carry on developing. If your pre-test works, you get told and your change set gets committed to the repository. If your pre-test fails, you get told, and you can fix any problems and try again. The point is, it's fire and forget but with no friendly fire.

Here is how I set it up. As you'd expect from JetBrains it's very easy.

1. Go to your TC project site. Select My Tools and settings, download the Add in for Visual Studio. Install it.

2. Restart VS (probably)

3. You should now have a TeamCity menu item.

4. Click Login, set your server details + login password you use to connect to TC.

5. If you don't have a SVN.exe, you need to get one! (if like me you are using TortoiseSVN, you need to do this)

   A. I used CollabNet's binaries. Download + install this version. Yes you have to register, no, that doesn't matter.

CollabNet Subversion Command-Line Client v1.6.3 (for Windows)

6. Click the Remote run command in VS (Remote run + pre-tested commit seem to be interchangeable terms)

7. Click the subversion tab

8. Set the path to svn.exe to C:\Program Files\CollabNet Subversion Client\svn.exe (by default installation of collabnet)

9. Set 'Use Subversion local copy authentication' if not already set

10. Set 'Detect subversion working copy automatically' if not already set

11. Go to the changes tab and select the build configuration you want to use for pre-tested commit. We have a commit checking config which compiles the trunk solution and runs our fast TDD tests.

12. Type in a commit comment + press run This took about a minute the first time I tried it, after that its faster!

* other continuous integration tools are available.

Wednesday 15 April 2009

NHibernate tips

Here is a collection of things I keep forgetting with NH: Getting any old client for testing : var client = session.CreateQuery("select from Client") .SetMaxResults(1) .UniqueResult();