qtクリエーターがファイルからデータを読み込んでいるかのようにstd::cin
. それは私が何かをしたいです
cat in.txt type | ./may_executable_file
同じデータを毎回コンソールに収集しないように、qtクリエーターでプログラムをテストするために必要です。
qtクリエーターがファイルからデータを読み込んでいるかのようにstd::cin
. それは私が何かをしたいです
cat in.txt type | ./may_executable_file
同じデータを毎回コンソールに収集しないように、qtクリエーターでプログラムをテストするために必要です。
istream
から直接ではなく から読み取るテスト可能なメソッドにプログラムを再構築することを検討する必要がありますcin
。例えば:
int do_work(std::istream& is, std::ostream& os)
{
int n, k;
is >> n >> k;
os << n << std::endl << k << std::endl;
}
int main()
{
do_work(std::cin, std::cout);
return 0;
}
これで、次のようなテスト ユニットを作成できます。
int test_work()
{
std::ifstream inf("test.txt");
std::stringstream out;
do_work(inf, out);
// Check out for results here.
}
別のオプションは、 http://qt-project.org/doc/qtcreator-2.5/creator-run-settings.html の実行設定で使用することCustom Executable
です。QCreator