0

I can read the Excel file perfectly, but not pass the parameters to the test.

[TestFixture]
public class MyTests
{
    [Test, TestCaseSource(typeof(MyDataClass), "TestCases")]
    public int DivideTest(int n, int d)
    {
        return n / d;
    }
}

public class MyDataClass
{
    public static IEnumerable TestCases
    {
        get
        {
            yield return new TestCaseData(12, 3).Returns(4);
            yield return new TestCaseData(12, 2).Returns(6);
            yield return new TestCaseData(12, 4).Returns(3);
        }
    }
}

That way you can pass data through IEnumerable. How did you date from an Excel file?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • excellent, thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuu – Miguel D'Alessio Nov 15 '17 at 17:08
  • What do you mean by *"How did you date from an Excel file?"* Do you mean *"How can you get data from an Excel file?"* (Including ***data*** instead of ***date***.) Respond by [editing your question](https://stackoverflow.com/posts/47295204/edit), not here in comments (if appropriate). – Peter Mortensen Jul 02 '19 at 21:57

1 Answers1

0

If you can read the Excel file already, you are almost there. All you need to do is loop through the rows in the spreadsheet, construct a TestCaseData object using the values from the columns of each row and then yield return the object.

Rob Prouse
  • 22,161
  • 4
  • 69
  • 89