Here's a feature idea for TestDriven.NET: when a test run completes,
play back a sound and display an icon in the status bar. The icon
should be green when the test run has completed successfully, red when
the test suite has yielded an error, and yellow when there was a
skipped test. The sound should indicate whether there was an error
(e.g., Hand sound) or not.
I've written a Macro that parses the output pane of TestDriven.NET and
notifies the user via "DTE.StatusBar.Animate(True, pathToBitmapFile)"
and "System.Media.SystemSounds.Hand.Play()". However,
DTE.StatusBar.Animate doesn't really work well with macros because
when the macro is reset (and it sometimes is), the icon won't be
cleared any more (this results in multiple icons).
For an add-in, this feature should be quite easy to add, I believe.
The icon adds to test result visualization, and the sound is
incredibly helpful with longer test runs where one tends to go read
some e-mails or blogs.
Regards,
Fabian
PS: For completeness, here's the macro code. Must be included with the
EnvironmentEvents module to work as is:
Dim RunAgain As Boolean = True
Dim LastAnimatedPicture As String = Nothing
Public Const AnimationFileName As String = "TestDriven.Animate.bmp"
Private Sub OutputWindowEvents_PaneClearing(ByVal pPane As
EnvDTE.OutputWindowPane) Handles OutputWindowEvents.PaneClearing
RunAgain = True
If LastAnimatedPicture IsNot Nothing Then
DTE.StatusBar.Animate(False, LastAnimatedPicture)
LastAnimatedPicture = Nothing
End If
End Sub
Private Sub OutputWindowEvents_PaneUpdated(ByVal pPane As
EnvDTE.OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
If RunAgain AndAlso pPane.Name = "Test" Then
Dim contents =
pPane.TextDocument.StartPoint.CreateEditPoint().GetText(pPane.TextDocument.EndPoint)
If contents = "" Then
Return
End If
Dim resultRegex = New Regex("(\d+) passed, (\d+) failed,
(\d+) skipped")
Dim result = resultRegex.Match(contents, RegexOptions.RightToLeft)
If result.Success Then
RunAgain = False
If Integer.Parse(result.Groups(2).Value) > 0 Then
System.Media.SystemSounds.Hand.Play()
AnimateImage(Drawing.Color.Red, TimeSpan.FromSeconds(2))
ElseIf Integer.Parse(result.Groups(3).Value) > 0 Then
System.Media.SystemSounds.Asterisk.Play()
AnimateImage(Drawing.Color.DarkGoldenrod,
TimeSpan.FromSeconds(2))
Else
System.Media.SystemSounds.Asterisk.Play()
AnimateImage(Drawing.Color.Green, TimeSpan.FromSeconds(2))
End If
End If
End If
End Sub
Sub AnimateImage(ByVal clr As Drawing.Color, ByVal length As TimeSpan)
Dim path As String =
System.IO.Path.Combine(System.IO.Path.GetTempPath(),
AnimationFileName)
Using img As New Bitmap(16, 16)
Using grfx = Graphics.FromImage(img)
Using brush = New Drawing2D.LinearGradientBrush(New
Point(0, 0), New Point(0, img.Height),
System.Windows.Forms.ControlPaint.LightLight(clr), clr)
grfx.FillRectangle(brush, New Rectangle(0, 0,
img.Width, img.Height))
End Using
img.Save(path, Imaging.ImageFormat.Bmp)
End Using
End Using
DTE.StatusBar.Animate(True, path)
LastAnimatedPicture = path
End Sub