OpenCover / opencover

A code coverage tool for .NET 2 and above (WINDOWS OS only), support for 32 and 64 processes with both branch and sequence points
https://blog.many-monkeys.com
Other
1.31k stars 247 forks source link

Method Not Covered #633

Closed jregnier closed 8 years ago

jregnier commented 8 years ago

Please provide the following information when submitting an issue, where appropriate replace the [ ] with a [X]

My Framework

My Environment

I have already...

My issue is related to (check only those which apply):

Expected Behavior

The following method should be fully tested by the test below.

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            List<List<string>> result = new List<List<string>>();

            var array = JArray.Load(reader);

            foreach (var item in array)
            {
                if (item is JArray)
                {
                    result.Add(((JArray)item).ToObject<List<string>>());
                }
                else if (item is JValue)
                {
                    result.Add(new List<string>() { ((JValue)item).Value.ToString() });
                }
            }

            return result;
        }

and this is what the test looks like. Its testing the method indirectly with a TestObject which has the attribute on one of its properties and also directly by calling the method from the test.

        [TestMethod]
        public void ReadJsonTest()
        {
            var json = File.ReadAllText("Dto\\BoosterCustomConverterData.json");

            var result = JsonConvert.DeserializeObject<RootSetDto>(json);

            Assert.IsNotNull(result.Set.Booster);
            Assert.AreEqual(16, result.Set.Booster.Count);

            JsonTextReader jsonReader = new JsonTextReader(new StringReader("[[\"rare\",\"mythic rare\"],\"uncommon\",\"uncommon\",\"uncommon\",\"common\",\"common\",\"common\",\"common\",\"common\",\"common\",\"common\",\"common\",\"common\",\"common\",\"land\",\"marketing\"]"));

            BoosterCustomConverter converter = new BoosterCustomConverter();
            var result2 = converter.ReadJson(jsonReader, typeof(List<List<string>>), null, null) as List<List<string>>;
            Assert.IsNotNull(result2);
            Assert.AreEqual(16, result2.Count);
        }

Actual Behavior

The method is reporting 0 coverage.

Steps to reproduce the problem:

Run OpenCover with following command .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"J:\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" -targetargs:"/noresults /noisolation /testcontainer:"".\MtgApiManager.Lib.Test\bin\Debug\MtgApiManager.Lib.Test.dll" -filter:"+[MtgApiManager.Lib]* -[MtgApiManager.Lib]MtgApiManager.Lib.Properties.*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\MtgApiManager.Lib_coverage.xml

sawilde commented 8 years ago

Please provide a working sample (not code snippets) so I can replicate your issue exactly.

jregnier commented 8 years ago

Thanks for the reply. Last night I decided to refactor my code and ended up not needing the method causing the issue so indirectly fixing my issue. Thanks