在 MSTest 中运行时动态创建单元测试方法
MSTest 中是否有相当于 SuiteBuilder 的工具?到目前为止还没有找到。
我有一堆 xml 文件,每个文件都被视为映射到一个测试方法。由于有数百个这样的项目,并且为每个项目手动编写测试,这不是一个好主意。
因此,在 nunit 中,您可以实现 ISuiteBuilder 并让测试用例动态运行并显示为许多测试方法。
我正在寻找一种方法在 MSTest 中做同样的事情。
我查看了 DataSource 属性,但它满足每个测试方法 1 个数据源 xml 文件/csv,迫使我编写 100 个测试方法。我还想将每个 xml 文件分开,不要将它们全部合并到 1 个大文件中,在这种情况下它将变得无法维护。
有人尝试过这个或者有什么建议吗?
Is there an equivalent of SuiteBuilder in MSTest? couldn't find one so far.
I have a bunch of xml files, each to be seen as mapped to a test method. As there are 100s of these and to manually write tests for each of these, is not a good idea.
So in nunit you could implement ISuiteBuilder and have the Test cases run dynamically and show up as those many test methods.
I am looking for a way to do the same thing in MSTest.
I've looked at DataSource attribute, but it caters to 1 datasource xml file/csv per test method, forcing me to write 100s of test methods. I also want to keep each xml file separate and don't club them all in to 1 huge file, in which case it would become unmaintainable.
Has someone tried this or has any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不完全符合您的要求,但您可以使用 pex 用于自动化和可参数化的白盒测试。这样,您就不需要手动完成所有这些事情。 Pex 支持 MSTest 以及 NUnit。生成的测试使用额外的文件,您不需要任何 xml 文件。
但我认为您无法轻松地使用 NUnit 中现有的 .xml 文件并使用 pex 与 MSTest 共享它们 - 如果这就是您的意图。
Not exactly what you asked for, but you can use pex for automated and parametrizable white box tests. In that way, you dont need to manually do all that stuff. Pex supports MSTest as well as NUnit. Generated Tests use an extra file, you don't need any xml files.
But I think you can't easily use your existing .xml files from NUnit and share them with MSTest using pex - if that is what you intended.
我已经这样做了。以下是您需要执行的操作:
测试:
MyTestData.xml:
test1.xml 和 test2.xml 必须存在于 MyTestData 目录中。
I have done this already. Here is what you would need to do:
The Test:
MyTestData.xml:
test1.xml and test2.xml must exist in the MyTestData directory.