Thursday, January 19, 2006

Start getting ready, TFS RC is on it's way.  Thank you Jeff for the heads up!

posted on Thursday, January 19, 2006 8:28:07 PM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
 Wednesday, January 18, 2006

Paulo Reichert posted a GREAT walkthrough / sample using the new Configuration Management features of .Net 2.0.

posted on Wednesday, January 18, 2006 6:51:24 AM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
 Tuesday, January 17, 2006

If you are using TeamBuild then this post is for you. 

In TeamExplorer when you create a new build type it will create a *.proj file.  During the creation of this build type, you will be asked which TestLists you would like executed in that build type.  Once completed if you open that proj file, you will see an item group that looks something like the following:

<ItemGroup>
  <MetaDataFile Include="$(SolutionRoot)\TestProject1\TestProject1.vsmdi">
    <TestList>TestList1;TestList2</TestList>
  </MetaDataFile>
</ItemGroup>

For this build type there are actually 2 different TestLists, TestList1 and TestList2.  These TestLists will get executed and reported on in the build.  With the out of box ItemGroup configuration both lists will actually roll up into one set of test results; but what if you wanted to to actually have multiple test runs for a given build. 

We can make a very slight modification to that generated code block and actually get a separate test run per test list.

<PropertyGroup>
  <VsmdiPath>$(SolutionRoot)\TestProject1\TestProject1.vsmdi</VsmdiPath>
</PropertyGroup>

<ItemGroup>
  <MetaDataFile Include="$(VsmdiPath)">
    <TestList>TestList1</TestList>
  </MetaDataFile>

  <MetaDataFile Include="$(VsmdiPath)">
    <TestList>TestList2</TestList>
  </MetaDataFile>
</ItemGroup>

More to come....

posted on Tuesday, January 17, 2006 11:50:43 PM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
 Monday, January 16, 2006

While you cannot validate you exception's message in the ExpectedException attribute all is not lost.  Lets walk through three scenarios.

In all three tests you will see an Assert.Fail in the try block.  You need this statement in case the target doesn't throw any exceptions, therefor failing the test.  The first example is a passing test, throw and exception with a message, catch it and compare the message string. 

   [TestMethod]
   public void PassingException()
   {
      const string expectedExceptionMessage = "Foobar Message";

      try
      {
         throw new ApplicationException( expectedExceptionMessage );
         Assert.Fail( "Expected an exception to get thrown by target" );
      }

      catch ( ApplicationException ex )
      {
         Assert.AreEqual<string>( expectedExceptionMessage, ex.Message );
      }
   }  

Here we see the same test failing only because the message contained in the exception is different.

   [TestMethod]
   public void FailingOnExceptionMessage()
   {
      const string expectedExceptionMessage = "Foobar Message";

      try
      {
         throw new ApplicationException( "Invalid" );
         Assert.Fail( "Expected an exception to get thrown by target" );
      }

      catch ( ApplicationException ex )
      {
         Assert.AreEqual<string>( expectedExceptionMessage, ex.Message );
      }
   }

While this last test follows the same pattern seen above the test is really only testing for the type of exception being throw.  This should be refactored to use the ExpectedException attribute.

   [TestMethod]
   public void FailingOnExceptionType()
   {
      const string expectedExceptionMessage = "Foobar Message";

      try
      {
         throw new Exception( expectedExceptionMessage );
         Assert.Fail( "Expected an exception to get thrown by target" );
      }

      catch ( ApplicationException ex )
      {     
      }

      catch
      {
         Assert.Fail( "Incorrect Exception type was thrown by target" );
      }
   }

Same test refactored, this test still fails but only to illustrate that example.

   [TestMethod, ExpectedException ( typeof ( ApplicationException) )]
   public void FailingOnExceptionType()
   {
      throw new Exception( "..." );
   }

posted on Monday, January 16, 2006 9:27:52 AM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
 Saturday, January 14, 2006

It was finally time to join the long list of fellow Microsoft bloggers.  You will now find a subset of http://csell.net content @ http://blogs.msdn.com/csell.

posted on Saturday, January 14, 2006 11:50:44 AM (Central Standard Time, UTC-06:00)  #    Comments [1] Trackback
 Friday, January 13, 2006

I love Virtual PC, and I use if for all of my development.  I have a ton of VPC's just sucking up MAJOR disk space. I ran across and article from Andrew ConnellHOWTO: Use Virtual PC's Differencing Disks to your Advantage.  I wish I would have known about that feature a few years ago...

posted on Friday, January 13, 2006 11:35:51 AM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback

If you've switched from NUnit to the VSTS Unit Testing then I am pretty sure you've used the ExpectedException attribute. If you haven't it looks something like this:

[ExpectedException( typeof( ApplicationException ), "Message" )]

Using it with a test would look like the following:

[TestMethod, ExpectedException( typeof ( ApplicationException ) ) ]
public void ut1()
{
   throw new ApplicationException();
}

[TestMethod, ExpectedException( typeof( ApplicationException ), "foo" )]
public void ut2()
{
   throw new ApplicationException("bar");
}

You would naturally expect test ut1 to pass and ut2 to fail.  ut2 should fail on the bases that the message contained within the exception was in fact different.  Not true.  Both actually pass and not because of a bug but rather a new feature introduced to the attribute.  The Message property is actually a message that prints out with the test when it fails; just like the optional message property you find on all of the Assert methods.

   Assert.IsTrue( false == true, "Developer put explanation if this test was to fail" );

That message will print with the output of the test like so:

Error 1 TestCase 'ExpectedExceptionTest.ExpectedException.ut3' failed: Assert.IsTrue failed. Developer put explanation if this test was to fail
at ExpectedExceptionTest.ExpectedException.ut3() in C:\MyPrograms\ExpectedException\ExpectedExceptionTest\ExpectedException.cs:line 26 C:\MyPrograms\ExpectedException\ExpectedExceptionTest\ExpectedException.cs 26 

Lets correct ut2:

[TestMethod, ExpectedException( typeof( ApplicationException ), "I failed because I am looking for the wrong excpeption type" )]
public void newUt2()
{
   throw new Exception( "foobar" );
}

This will in fact fail because the Exception type thrown was different.  When it fails we will see that message in the output.

Having said all that, there is in fact a bug.  When you run a test with that ExpectedException attribute in Visual Studio you will not see the message on the failure output; if you run it in MSTest.exe you will.

ExpectedException.cs (.75 KB)

posted on Friday, January 13, 2006 11:34:54 AM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
 Friday, January 06, 2006

I started to host my own servers about 6 years ago.  It started as a learning exercise and things have just evolved into a full time thing. 

I have both Linux and Windows running for a number of reasons.  Both are patched nightly and I do my best to run both platforms as any enterprise shop would ( with the resources I can afford ).

Having said that my Linux machine was compromised causing me a great deal of pain and frustration. Things are almost back to normal.

Just don't ever forget the Internet is the wild wild west.

posted on Friday, January 06, 2006 11:03:54 AM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback