jeudi 29 octobre 2015

Why code coverage reports call with null arguments not been covered

Given I have the following test

    public class PatientRepositorySpec
    {
        [Fact]
        public void given_null_as_MongoOptometricInterpretationPaths_when_Ctor_then_throw_exception()
        {
            var ex = Assert.Throws<ArgumentNullException>(
                () => new PatientRepository(null, Substitute.For<IMongoCollectionFactory<BsonDocument>>())
                );
            Assert.Contains("mongoPaths", ex.Message);
        }
  }

The visual studio code coverage mark the code () => new PatientRepository(null, Substitute.For<IMongoCollectionFactory<BsonDocument>>() as not been covered. but the test pass and in order to do that code line has to be executed.

I've detected that with that pattern visual studio always says the code is no been covered when I have a call with a null argument inside the expression.

Does anyone know why visual studio labeled that line as no been covered?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire