Skip to content

Get function arguments from test cases specified via Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute #129

@BenVoigt

Description

@BenVoigt

The MSTest Framework v2 (preview available in nuget) supports providing test cases in source code via attributes. Example in a real test for code I've been working on:

    [TestMethod]
    [DataRow("45.916667N", 45.916667)]
    [DataRow("45,916667N", 45.916667)]
    [DataRow("45.916667 N", 45.916667)]
    [DataRow(" 45.916667N", 45.916667)]
    [DataRow("+45.916667", 45.916667)]
    [DataRow(" +45.916667", 45.916667)]
    [DataRow("45 55.2' N", 45.92)]
    [DataRow("45 55.2'N", 45.92)]
    [DataRow("+45 55.2'", 45.92)]
    [DataRow("+4555.2", 45.92)]
    [DataRow("45°55'00.0\"N", 45.916667)]
    [DataRow("45°55'00.0''N", 45.916667)]
    [DataRow("45° 55' 00.0\" N", 45.916667)]
    [DataRow("45°00.0\"N", 45.0)]
    [DataRow("45°00.0''N", 45.0)]
    [DataRow("+50", 50.0)]
    [DataRow("50",  50.0)]
    public void ValidLatitudes(string input, double expectedLatitude)
    {
        GeodeticAngle result;
        bool success = GeodeticParser.TryParseLatitude(input, out result);

        Assert.IsTrue(success);
        Assert.AreEqual(expectedLatitude, result.Degrees, .00001);
    }



    [TestMethod]
    [DataRow("abc")]
    [DataRow("+45.916667N")]
    public void InvalidLatitudes(string input)
    {
        GeodeticAngle result;
        bool success = GeodeticParser.TryParseLatitude(input, out result);

        Assert.IsFalse(success);
    }

It would be great if I could trace through these using Alive. Right now, however, if I pick a test and say "run this method directly", the prompt for arguments pops up, and if I do "run this method via a test case", it errors out with "There were errors instrumenting your code. CS7036 There is no argument given that corresponds to the required formal parameter".

I think it would be tremendously helpful if Alive were to read DataRow attributes in the source code. It could even offer to write new ones based on the actual parameters typed into the "run this method directly" dialog.

At the very least, entering values into the argument dialog should work -- right now no matter what values are specified, if the target is a TestMethod with arguments, I get the same errors as if I ran as a test case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions