Same question can be found at:
http://stackoverflow.com/questions/27934297/ncrunch-unit-testing-code-coverageIn my Visual Studio 2013 projects I am getting uncovered unit test warning from NCrunch where those functions have strong dependency to other entities. I would like to learn is there any natural way to clear out those warnings.
Lets assume I have a person class like this;
public class PersonApiHandler{
public virtual Person GetPersonFromFacebook(){
// heavy facebook api call here
return person; }
}
and I have a fake class like;
public class PersonApiHandlerFake: PersonApiHandler
{
public override Person GetPersonFromFacebook(){
// fake person is returning - isolated
return fakeUser;
}
}
then I am calling this method like;
[TestFixture]
public class PersonApiHandlerTests(){
[Test]
public void GetPerson_from_Api_success(){
PersonApiHandlerFake fake = new PersonApiHandlerFake();
var fakeFacebookUser = fake.GetPersonFromFacebook();
Assert.IsNotNull(fakeFacebookUser );
}
in this case NCrunch complains about PersonApiHandler.GetPersonFromFacebook is not code covered. Since this function calls real API, I cannot use it in my unit tests. Only way I found out using [ExcludeFromCodeCoverage] attribute to disable this warning. Is it right way to do or is there any other way to clear out uncovered code messages?