[英]test input/output of Visual Studio 2012 console application
I am working on a program which reads some input from standard-in, processes it, and writes some output to standard out. 我正在研究一个程序,它从标准输入读取一些输入,处理它,并将一些输出写入标准输出。 So that I don't have to type in sample/test input every time, I have saved the input to a TXT file, and the corresponding expected output to another TXT file. 因此,我不必每次都输入样本/测试输入,我已将输入保存到TXT文件,并将相应的预期输出保存到另一个TXT文件。
How can I run my executable (preferably in either Debug or Release mode, or potentially under profiler) such that VS automatically feeds in the input TXT file? 如何运行我的可执行文件(最好是在Debug或Release模式下,或者可能在profiler下),以便VS自动输入输入TXT文件? Can VS automatically check the output of the program vs the expected output TXT file? VS能否自动检查程序的输出与预期的输出TXT文件? It would be great if it would show me a side-by-side diff if they are not the same. 如果它们不同的话,它会向我展示一个并排的差异会很棒。 Can I set up the testing framework to run various tests with different input/expected output files? 我可以设置测试框架以使用不同的输入/预期输出文件运行各种测试吗?
Note that I can't just use normal unit testing since I have to do integration testing. 请注意,我不能只使用正常的单元测试,因为我必须进行集成测试。
EDIT: for what it's worth, I'm using C++. 编辑:为了它的价值,我正在使用C ++。
As mentioned above , you can redirect input from some file. 如上所述 ,您可以从某个文件重定向输入。
Similarly, you can redirect output to some temporary file and then invoke some diff tool to compare your files: 同样,您可以将输出重定向到某个临时文件,然后调用一些diff工具来比较您的文件:
In the "Command Arguments" property of "Debugging" category of project properties add: 在“调试”类别的项目属性的“命令参数”属性中添加:
> actual.out.txt && diff actual.out.txt expected.out.txt
You can replace diff
with any apropriate diff tool. 您可以使用任何适当的diff工具替换diff
。
Generally, you can invoke any script after your program execution using &&
. 通常,您可以在程序执行后使用&&
调用任何脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.