Context Sensitive Run *All* Tests with TestDriven.NET


I just tweaked my previous entry's macro to be more context sensitive if you have a lot of test fixtures and do not want to run all of them in your solution.  If you are in a code window with a project, the macro will select that project and run the tests for it.  If you are in any other window, it will just run all the tests.  This could be useful if you have a number of projects in the same solution, all with test fixtures but only need to run a single test fixture instead of them all.

Sub RunProjectTests()
Dim LastWindow As Window
LastWindow = DTE.ActiveWindow
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()

Dim SolutionName As String
SolutionName = System.IO.Path.GetFileNameWithoutExtension( _
DTE.Solution.FullName)

Try
Dim
ProjectName As String
ProjectName = System.IO.Path.GetFileNameWithoutExtension( _
LastWindow.Project.FullName)
DTE.ActiveWindow.Object.GetItem(SolutionName + "\" + ProjectName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
Catch ex As Exception
'Fall back and just run all the test fixtures in the solution
DTE.ActiveWindow.Object.GetItem(SolutionName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
End Try

DTE.ExecuteCommand("TestDriven.NET.Client")
System.Threading.Thread.Sleep(150)
LastWindow.Activate()
End Sub

I'm not a Visual Basic programmer so these macros could blow up in weird ways if you use them in certain situations like opening a single file in Visual Studio without a solution.

It's getting late, so time for bed.

Tags: ,

author: Ted Milker | posted @ Saturday, March 01, 2008 1:18 AM | Feedback (0)

Run *All* Tests with TestDriven.NET


One thing that has always bugged me about TestDriven.NET is that there does not seem to be a way to run all the tests in your entire solution.  Nor is there one to run all the tests in the project of the current file you are in.  The Visual Studio commands TestDriven.NET.Client and TestDriven.NET.RunTests commands are always context sensitive.  If you are in a specific test method, then TestDriven.NET only runs that single test.  If you are in a TestFixture but outside any method, then it runs the whole fixture.  You can always right click in the Solution Explorer and pick Run Tests but I like to keep my hands on the keyboard as much as possible.

Tonight, I had had enough and went searching.  According to Scott Hanselman, at one time, there was a TestDriven.NET.Solution command which sounds like it would do what I wanted but it appears to be long gone.  I found a blog entry from 2006 by Joe White that uses a Visual Studio macro to make TestDriven.NET behave.  I had never used the Macro Explorer before but it is pretty simple.  Using Joe's macro as a base, I came up with:

Sub RunAllTests()
Dim LastWindow As Window
LastWindow = DTE.ActiveWindow
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
Dim SolutionName As String
SolutionName = System.IO.Path.GetFileNameWithoutExtension( _
DTE.Solution.FullName)
DTE.ActiveWindow.Object.GetItem(SolutionName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("TestDriven.NET.Client")
System.Threading.Thread.Sleep(150)
LastWindow.Activate()
End Sub

Joe automatically switched to the output window at the start of the macro, I removed this because TestDriven.NET already does this.  Which brings up another annoying feature of TestDriven.NET, I wish I could turn it off and just have it post to the status line.  I store the last window for later because the macro has to switch the focus to the Solution Explorer to run the command.  The Sleep call is so that TestDriven.NET has enough time to think the context is set to the root of the Solution Explorer instead of wherever you happen to be.  Without it, it switches back and forth too quickly on my computer and TestDriven.NET just runs the command in whatever context it determines.  You may need to tweak the number if your computer is faster or slower.  I found it would still work at 100 but not at 50, so I just set it to 150 to be sure.  It switches fast enough that it is not troublesome to my workflow.

author: Ted Milker | posted @ Saturday, March 01, 2008 12:25 AM | Feedback (0)

Refactoring My Wetware


I am finding switching to Test Driven Development to be pretty tough after years and years of just "roughing it."  I read The Pragmatic Programmer: From Journeyman to Master years ago(and need to re-read) and enjoyed it very much.  I do not know how much I actually took away from it but I know it helped.  I have also read a couple other books from The Pragmatic Programmers and decided to pick up a beta book titled Refactor Your Wetware: Pragmatic Thinking and Learning.  Review to come once I finish.

Tags: ,

author: Ted Milker | posted @ Monday, February 25, 2008 9:12 AM | Feedback (0)

Test-Driven Development


I have been programming for a long time.  I would have to say that it became more "serious" when I was 16 in high school.  I went to an ACM programming competition with a good friend at his high school(the "rich kids" high school).  We ended up winning.  Since that time, programming has always been a part of my life.  Whether it was tinkering with the Linux kernel to get a rough driver working for NaturalPoint's TrackIR, playing with game development or just ripping out a quick script or utility app, it was something I was always doing.  Programming became my profession in 2000 when I started developing the website for the company I work for.  Through it all, following the conventional method of writing code I think would work and then testing and trying to break it.

So it feels like I have been programming for ages(really, about 14 years) and I get quite a bit done the way I do it.  Last year, I decided that I wanted to formalize the testing process and Test Driven-Development(TDD) felt like it was what I had been doing for years but instead of keeping the tests, throwing them out.  I did a lot of reading about it but never had the time or the right environment to actually implement it in my daily process.  Things have improved and I now have the chance.  However, I am finding it extremely difficult.

I think most of my trouble is just coming from a new way of looking at things and the way I am supposed to develop under TDD.  It is difficult to think in terms of tests and writing them first when it is so easy to just type up the code and get something running immediately.  I am forcing myself to follow the process, however, because I want to develop the correct habit.  TDD has already given me insight into how to get something done, simply by forcing me to think more about what I am doing rather than banging out code the way I may have solved a similar situation in the past.

Tags:

author: Ted Milker | posted @ Thursday, February 21, 2008 7:08 AM | Feedback (0)

Blog 2.0


Well, that went well.  A total of three posts the first couple days after I set up the blog and then nothing.  However, after some changes at work and keeping a diary there about things I get done, I think I might be able to keep up on this, this time around.

Things are pretty much the same.  I have been learning a lot about .NET, mostly WPF.  Since Silverlight 2.0 is not available yet, WPF is a good way to get experience that can be used once it is.

Japanese

I have also been spending a lot of my personal time learning Japanese.  It is going really well in my opinion.  I am currently using the Pimsleur audio series and transcribing each lesson to text before each daily lesson.  This helps reinforce the previous lesson and also helps with pronunciation.  Audio alone, however, is not enough.  I have also been studying a number of books whenever I have a question about what the audio lesson is teaching me.  Some good references that I have found:

  • Japanese The Manga Way: An Illustrated Guide to Grammar and Structure by Wayne P. Lammers
  • Remembering the Kana by James W. Heisig
  • Companion site to Japanese Verbs: Saying What You Mean by Tim R. Matheson

author: Ted Milker | posted @ Wednesday, February 20, 2008 8:13 AM | Feedback (0)

My First Blog


Well, this is my first real blog.  Not really much to say at the moment.  I have a great idea for lightMind.NET and I will post more details about it soon.  This is going to be mostly a technical blog, leaning towards my new found love of all things .NET especially ASP.NET and related technologies.

A little about myself:  I am coming from a PHP/Flash background and jumping feet first into ASP.NET and Silverlight.  I have been developing websites and web-based applications for my employer for over 7 years now.  I finished a pretty big application a couple months ago which manages all of our customer information(a CRM app).  I learned a lot developing that application but I learned a lot more about how much I need to formalize my development habits and start using some of the great tools that are available.  I have been putting together a .NET toolbox to help me start off on the right foot:

I am also extremely interested in XNA and development for the Xbox 360, so I am sure I will have various ramblings about that as well.

author: Ted Milker | posted @ Friday, June 08, 2007 9:08 PM | Feedback (1)