Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception during run UT with TestCaseSource #146

Open
comradum opened this issue Oct 13, 2016 · 8 comments
Open

Exception during run UT with TestCaseSource #146

comradum opened this issue Oct 13, 2016 · 8 comments
Milestone

Comments

@comradum
Copy link

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.b__1(XElement ts)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.<UnionIterator>d__661.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__162.MoveNext()
at System.Linq.Lookup2.CreateForJoin(IEnumerable1 source, Func2 keySelector, IEqualityComparer1 comparer)
at System.Linq.Enumerable.d__374.MoveNext() at OpenCover.UI.Processors.NUnitTestExecutor.UpdateTestMethodsExecution(IEnumerable1 tests)
at OpenCover.UI.Commands.ExecuteSelectedTestsCommand.b__1()

Versions used:

  • OpenCover exe: 4.6.519
  • OpenCover.UI: 0.8.1
  • Visual Studio (inc. SP number): VS 2012 11.0.61219.00 Update 5
  • MsTest/NUnit/xUnit: NUnit: 2.6.4
@MelleKoning
Copy link
Contributor

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
Copy link
Author

comradum commented Nov 7, 2016

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
Copy link
Contributor

pver commented Nov 7, 2016

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
Copy link
Contributor

pver commented Nov 7, 2016

See also #42

@comradum comradum added this to the Release 0.8.x milestone Nov 7, 2016
@MelleKoning
Copy link
Contributor

@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
Copy link
Author

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
Copy link
Author

@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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants