Search code examples
c#unit-testingnunit

How can I access the TestAdapter within my TestMethod


I want to access the ExpectedResult from my TestMethod

[TestMethod]
[TestCase("Pass", ExpectedResult = 1)]
[TestCase("Fail", ExpectedResult = 0)]
[TestCase("PassDueToExpectError", ExpectedResult = -1)]
public int Test(string msg)
{
    int ret = 0;

    switch (msg)
    {
        case "Pass":
            return 1;
        default:
            ret = 0;
            break;
    }
    if (/* ExpectedResult < 0 */) //<- How to test ExpectedResult?
    {
        return -1;
    }

    ret.Should().BeGreaterThan(0);
    return 0;
}

Any idea how I can access the ExpedtedResult?


Solution

  • Found following solution, by using:

    NUnit.Framework.TestContext.CurrentContext.Test.ExpectedResult