简体   繁体   English

测试Visual Studio 2012控制台应用程序的输入/输出

[英]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.

相关问题 在Visual Studio 2012控制台应用程序中创建窗口? - Create a Window in a Visual Studio 2012 console application? Visual Studio 2012-嵌入式输出控制台而不是cmd? - Visual Studio 2012 - Embedded output console instead of cmd? 如何在Visual Studio 2012单元测试中获取控制台输出 - How to get console output in Visual Studio 2012 Unit Tests Visual Studio 2012 C ++控制台应用程序立即退出 - Visual Studio 2012 C++ console application exits Immediately 在Visual Studio 2012中对C ++控制台应用程序进行单元测试 - Unit testing c++ console application in Visual Studio 2012 如何在Visual Studio 2012上使用带有控制台的GUI Windows应用程序? - How to use GUI Windows Application with Console on Visual Studio 2012? 将控制台应用程序的输出直接输出到 Visual Studio 而不是外部 Windows 控制台 - Make output of console application directly into Visual Studio and not external Windows console Visual Studio 2012中的Google Test - Google Test in Visual Studio 2012 Visual Studio 2012文件输入 - Visual Studio 2012 File Input 如何在Visual Studio 2012中向C ++控制台程序添加单元测试? - How can I add a unit test to a C++ console program in Visual Studio 2012?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM