Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
Created April 3, 2012 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoryyoung/2290767 to your computer and use it in GitHub Desktop.
Save gregoryyoung/2290767 to your computer and use it in GitHub Desktop.
xunit example
A profiler can quite easily find the constructor call to default constructor on this code:
[Fact]
public void ModestCreatesParameterWithBlah(){
var p = new MultiOrderedConstructorType();
p.Number = ...;
Assert.AreEqual(0, p.Number);
}
but on this it is created outside the scope of the test (its done internally by xunit)
[Theory, AutoData]
public void ModestCreatesParameterWithBlah([modest] MultiOrderedConstructorType x) {
Assert.AreEqual(0, x.Number);
}
in the first example the call to the constructor when looking at the current stack is under the context of a test. the second is not.
How would a coverage tool know to associate the constructor called before the test internally to xunit to the Theory?
@gregoryyoung
Copy link
Author

gregoryyoung commented Apr 3, 2012 via email

@sgryt
Copy link

sgryt commented Apr 3, 2012

I haven't heard of any other unit testing frameworks that can be customized wrt object construction (but @ploeh can probably say more about that) for test method parameters, but that is probably just due to the fact that I haven't done enough research. I'll be very interested in hearing about your findings, though.

My personal primary interest is to have the profiling test coverage counters be as inclusive as possible - for my code. I'm curious as to why you think I would be interested in test coverage for code that is not under my control, or the intricate details as of how xUnit internals wire stuff together? It doesn't matter that much to me to see a connected call chain containing both the object construction and the test method - I'm just really keen on having the AWESOME in-your-face visibility of test coverage for the largest possible part of my codebase.

I certainly understand your worries - that's why I propose that MM users take that part of the responsibility themselves - with a plugin implemetation of their own, targeted at a specific unit testing framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment