OpenCoverUI / OpenCover.UI

Visual Studio Integration to OpenCover
MIT License
77 stars 46 forks source link

Exception during run UT with TestCaseSource #146

Open comradum opened 8 years ago

comradum commented 8 years ago

Issue description:

Have exception: "Length cannot be less than zero" when start UT with TestCaseSource:

Length cannot be less than zero. Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length) at OpenCover.UI.Processors.NUnitTestExecutor.ReadTestCase(XElement ts) at OpenCover.UI.Processors.NUnitTestExecutor.b1(XElement ts) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Enumerable.d661.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.d162.MoveNext() at System.Linq.Lookup2.CreateForJoin(IEnumerable1 source, Func2 keySelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.d374.MoveNext() at OpenCover.UI.Processors.NUnitTestExecutor.UpdateTestMethodsExecution(IEnumerable1 tests) at OpenCover.UI.Commands.ExecuteSelectedTestsCommand.b__1()

Versions used:

MelleKoning commented 8 years ago

Can you show the testclass source that causes this exception? OpenCover.UI has unit tests to ensure discovery of tests work, so we might have missed your test scenario?

comradum commented 8 years ago

Please:

namespace ResultTest
{
   [TestFixture]
   public class TryParseNumericResult
   {
      public IEnumerable GetTestCases()
      {
         yield return
            new TestCaseData(">50").SetName("Greater than 50")
               .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.GREATER));
         yield return
            new TestCaseData("<50").SetName("Less than 50")
               .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.LESS));
         yield return
            new TestCaseData("50").SetName("Equal to 50")
               .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.EQUAL));
         yield return
            new TestCaseData("N50").SetName("Alphanumeric result result")
               .Returns(new Tuple<decimal?, ConditionType>(null, null));
      }

      [Test]
      [TestCaseSource("GetTestCases")]
      public Tuple<decimal?, ConditionType> TestTryParseNumericResult(string value)
      {
         decimal? numericValue;
         ConditionType conditionType;
         Result.TryParseNumericResult(value, out numericValue, out conditionType);
         return new Tuple<decimal?, ConditionType>(numericValue, conditionType);
      }
   }
}

Unfortunately I can't share all test dependencies. But test without corrections as shown above.

pver commented 8 years ago

The same issue was reported here: #90

It might have been solved already by merging in #117 (which also already included test cases for this) Although someone reported issues with it, so we need to retest that..

pver commented 8 years ago

See also #42

MelleKoning commented 7 years ago

@comradum I implemented your testcode to try it, and it seems to work.

Had to add a few methods that were missing from your post. this is the class I eventually had:

` namespace OpenCover.UI.TestDiscoverer.TestResources.NUnit {

[TestFixture]
public class DynamicTestcaseTests
{
    public enum ConditionType
    {
        GREATER,
        LESS,
        EQUAL
    }

    public IEnumerable GetTestCases()
    {
        yield return
           new TestCaseData(">50").SetName("Greater than 50")
              .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.GREATER));
        yield return
           new TestCaseData("<50").SetName("Less than 50")
              .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.LESS));
        yield return
           new TestCaseData("50").SetName("Equal to 50")
              .Returns(new Tuple<decimal?, ConditionType>(50, ConditionType.EQUAL));
        //yield return
          // new TestCaseData("N50").SetName("Alphanumeric result result")
            //  .Returns(new Tuple<decimal?, ConditionType>(null, null));
    }

    [Test]
    [TestCaseSource("GetTestCases")]
    public Tuple<decimal?, ConditionType> TestTryParseNumericResult(string value)
    {
        decimal numericValue = 50;
        ConditionType conditionType = TryParseNumericResult(value);
        return new Tuple<decimal?, ConditionType>(numericValue, conditionType);
    }

    public ConditionType TryParseNumericResult(string value)
    {
        char ch = value[0];
        if (ch == '5')
        {
            return ConditionType.EQUAL;
        }
        if (ch == '<')
        {
            return ConditionType.LESS;
        }
        return ConditionType.GREATER;
    }
}

}`

Ran this with the latest version of OpenCover and got this on screen:

image

So, seems to work, unless your implementation of certain methods is different. Can you try with the latest build from github?

comradum commented 7 years ago

Where I can found built binaries? Or I should build them myself? Also I have noticed that my problem already fixed, but I can't find any release with this problem fixed.

comradum commented 7 years ago

@MelleKoning, I have release version 0.8.1 installed. I see that after release there were commits on master that can fix my problem.

Are new release builds planned? If yes - when?

MelleKoning commented 7 years ago

Hi @comradum, Yes you have to build the extension from sources. @pver do you know who can warrant a release?