Automated testing of C++ console app in Visual Studio by sending text files to stdin?
I am going to take part in a coding contest my University is organizining next week. I am only allowed to use C or C++ and I would prefer to use the latter one using Visual Studio 2010. For every task there is a text input pr开发者_运维百科ovided as plaintext to stdin, for example:
200 100 10
2 11
I need a tool which would assist me with running my code with some pre-defined text file as stdin input.
On a unix-based system I would just use something like:
gcc mycode.cpp
./mycode.o <test1.in >result1.out
diff result1.out test1.out
Is there any way to reach this in Visual Studio 2010.
Or maybe one could recommend a nice C++ IDE with rich debugging functions which would have something like this "out of the box"?
With best regards, Alexander.
You can do essentially the same thing with the Visual Studio compiler and the Windows command line:
cl /EHsc mycode.cpp
mycode.exe <test1.in >result1.out
fc result1.out test1.out
Though you might want a better diff tool than fc
.
You can also code up your code so the routine that does the real work is called with stream handles (or some other mechanism to get and put the data) and have a test build feed the data through files that it opens instead of stdin
and stdout
. When your testing is done, the real program simply calls that routine with the stdin
and stdout
handles.
There are unit test frameworks for C++ that might help you with that, but getting one of them installed and integrated in might be more trouble than just writing your own simple test jig.
精彩评论