How can I pass dynamic objects into an NUnit TestCase function?

后端 未结 4 684
忘了有多久
忘了有多久 2020-12-12 22:10

I am writing a data-intensive application. I have the following tests. They work, but they\'re pretty redundant.

[Test]
public void DoSanityCheck_WithCountEqu         


        
4条回答
  •  情话喂你
    2020-12-12 22:12

    I pass strings that I parse sometimes, and I think it reads pretty well.

    Example:

    [TestCase("15°", "-10°", 25, typeof(Degrees))]
    [TestCase("-10°", "15°", -25, typeof(Degrees))]
    [TestCase("-10°", "0°", -10, typeof(Degrees))]
    [TestCase("-90°", "1.5707 rad", -3.1414, typeof(Radians))]
    [TestCase("1.5707 rad", "-90°", 3.1414, typeof(Radians))]
    [TestCase("1.5707 rad", "1.5707 rad", 0, typeof(Radians))]
    public void SubtractionTest(string lvs, string rvs, double ev, Type et)
    {
        var lv = Angle.Parse(lvs);
        var rv = Angle.Parse(rvs);
        var diff = lv - rv;
        Assert.AreEqual(ev, diff.Value, 1e-3);
        Assert.AreEqual(et, diff.Unit.GetType());
    }
    

提交回复
热议问题