views:

50

answers:

1

In a C# class library, and set of tests. Everything was going well until I added a new set of tests - they run correctly on my machine, but fail on the TFS Build server. The stack trace in the build log makes no sense - the constructor of one class appears to be mapped to one of it's methods.

If my class looks a little like this:

1.  public class ClassToBeTested   
2.  {
3.  
4.      /// <summary>
5.      /// Default constructor.
6.      /// </summary>
7.      public ClassToBeTested()
8.      {
9.  
10.     }
11. 
12.     /// <summary>
13.     /// Default constructor.
14.     /// </summary>
15.     public MethodToTest()
16.     {
17.         /* do stuff that throws exception */
18.     }
19. 
20. }

And in my unit test class I have this:

1.  [TestMethod()]
2.  public void UpdateTest()
3.  {
4.       ClassToBeTested Target = new ClassToBeTested();
5.       ClassToBeTested.MethodToTest();
6.  }

Then my stack trace indicates this:

Test method unittestclass.UpdateTest threw exception /whatever/
ClassToBeTested.MethodToTest() : Line 17
unittestclass.UpdateTest() : Line 4

How is this possible?

+1  A: 

I think the code inside the method that throws an exception may have something to do with it. especially if something in there has a static constructor: perhaps this may shed some light:

http://msmvps.com/blogs/jon_skeet/archive/2010/01/26/type-initialization-changes-in-net-4-0.aspx

but for more help... perhaps the missing code method details and/or exception type.

Also check that your build configuration on your debug machine is the same as your build server.. or try testing in publish/release configuration

Maslow
+1 for reminding me to read John's blog, and the interesting possibility, even if that isn't what is happening here.
Peter LaComb Jr.