且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将内联变量添加到理论 xUnit

更新时间:2023-12-01 22:10:16

您可以使用 const string home = "test" 来实现,因为那将是一个常量表达式.

You could do it with const string home = "test" because that would be a constant expression.

您还可以使用 MemberData 属性来指向 yield return new object[]{ "test" }; 的内容,这在这方面更加复杂情况下,但在不必保持不变方面更加灵活,并允许您生成许多这样的数组,以便对不同的数据集重复执行测试.

You could also make use of the MemberData attribute to point to something that does yield return new object[]{ "test" }; which is more convoluted in this case, but more flexible in terms of not having to be constant, and allowing you to yield many such arrays to have the test done repeatedly on different sets of data.