Visual Studio 中的文件驱动单元测试? [英] File-driven unit tests in Visual Studio?

查看:22
本文介绍了Visual Studio 中的文件驱动单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为类库创建单元测试.有数百个测试,但它们都在测试同一个方法.唯一的区别是输入和输出.我想将这些测试的定义移动到某种文本文件中,以便我可以更方便地管理它们.

I am creating unit tests for a class library. There are hundreds of tests, but they're all testing the same single method. The only difference is the inputs and outputs. I'd like to move the definitions of these tests to some kind of text files so I can manage them more conveniently.

我可以创建一个适配器以便我可以继续使用 VS 测试运行器吗?我发现了一些对 [DataSource] 属性的引用,但我更喜欢在单独的文本文件中进行测试,而不是某种可查询的数据库.

Can I create an adapter so that I can continue to use the VS test runner? I found some references to [DataSource] attributes, but I'd prefer to have the tests in separate text files, not some kind of queryable database.

推荐答案

如果您使用的是 MSTest V2,您可以使用基于属性的数据输入,就像 @Floris 的示例在 xUnit 中所做的那样.请参阅 https://blogs.msdn.microsoft.com/devops/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ 用于公告,它应该看起来像这个:

If you are using MSTest V2, you can use attribute-based data inputs like @Floris' example did with xUnit. See https://blogs.msdn.microsoft.com/devops/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ for the announcement, and it should look something like this:

[DataTestMethod]
[DataRow("filename1")]
[DataRow("filename2")]
public void MyTestMethod(string inputfile)

这篇关于Visual Studio 中的文件驱动单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆