开发者

How could the stack trace for my unit test not match the actual source?

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.     /// Defa开发者_C百科ult 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜