用于单元测试的 XML 数据
我们希望通过一些单元测试来运行大量数据。我们希望在某种 Excel 电子表格或 XML 文档中定义它。
是否有办法让单元测试框架加载这些数据作为输入和期望。
我可以预见这会出现异常捕获的问题。对此的任何评论也将受到赞赏。
We are looking to run a large amount of data through some unit tests. We would like to define this in some sort of excel spreadsheet or XML document.
Is there away to get the unit testing framework to load this data as input and expectations.
I can foresee this having issues with exception catching. Any comments on this are appreciated as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
nUnit 装置只是 POCO,因此您可以使用 .NET 类以任何您喜欢的方式进行设置。因为它可能包含大量数据,所以我可能会将其设置在 TestFixtureSetUp 中,该测试为整个套件运行一次:
nUnit fixtures are just POCO's so you can really set it up however you like using .NET classes. Because it could be a lot of data I would probably set it up in a TestFixtureSetUp which is run once for the entire suite:
我花了几个小时寻找有关如何执行此操作的信息(因为数据中嵌入了一些格式,因此我无法使用 CSV 文件),我设法弄清楚如何将 XML 与 MSTest 一起使用。
这是一个小样本。希望有帮助。
假设您有一个简单的类库:
因此,将检查此方法的一部分的单元测试将如下所示:
xml 文件 TestStrings.xml 如下所示:
Having just spent a few hours looking for something on how to do this (because the data had some formatting embedded in it so I couldn't use a CSV file) I managed to work out how to use XML with MSTest.
This is a small sample. Hope it helps.
Suppose you have a simple class library:
So a unit test that will check out part of this method will look like this:
The xml file TestStrings.xml looks like this:
MBUnit 可以从 XML 文档或数据库等数据源驱动测试。
MBUnit can drive tests from data sources such as XML documents or databases.
对于 MSTest,请查看 数据源< /a> 属性。
For MSTest, take a look at the DataSource attribute.