AkideLiu:C++小白,最近写的小 demo 用到了 Gtest 的 unit test 大多数的 function
但是当主函数根据用户的输入( cin )来传值给 function 的时候如何测试呢?
暂时想到的方法就是把需要输入的内容用 txt 文件进行保存,然后用./executable < input.txt 的方式进行比模拟用户输入。
大概测试思路如下:
https://stackoverflow.com/questions/11408020/c-testing-with-input-cases-from-text-files
然后写成 shell 脚本:
EXEFile=$(find "$(pwd -P)" -name 'GTestSelfInput' | head -1)
cd $CURRENT_DIR
$EXEFile --gtest_filter=People_Services_input.initPassword01 < input1.txt
if [ $? != "0" ]; then
exit 1
fi
然后通过不同模拟的 input.txt 传入的参数再使用 Gtest 去确认操作是否成功。
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
//init password successes
TEST(People_Services_input, initPassword01) {
Storage::setSUserId(1);
EXPECT_TRUE(PeopleServices::initPassword());
People *p = PeopleDao::selectOnePeople(1);
EXPECT_EQ(p->getPassword(), "password123");
mysql::connection db = database_connection::getConnection();
db.execute("UPDATE oop.people t SET t.password = '-1' WHERE t.user_id = 1;");
delete p;
}
但是这样有很大的局限性,比如没办法随机生成输入内容,使用起来也非常不方便。
有没有什么测试框架可以解决这样的问题呢?( system testing,functional testing )
lcdtyph:如果是用 std::cin 做输入的话可以覆盖它的 rdbuf
```
#include <iostream>
#include <sstream>
int main() {
std::string fake_input = "abc";
std::istringstream iss{fake_input};
std::cin.rdbuf(iss.rdbuf());
std::string a;
std::cin >> a;
std::cout << a << std::endl;
return 0;
}
```
ZakaryTime:我有一个资料的路径如下:E:@大坪村扶贫工作\工作资料\台账&花名册\02.贫困户花名册.xlsx 目前我只记得住在一个 [台账] 文件夹下有 一个叫 [贫困户] 的东西,请问如何搜索。 已经试过:台账\ 贫困户zhouts:贫困户 .xlsx cheese:直接搜贫困户不行嘛? songer:E:\大坪村扶贫工作\工作资料\台…
请教 notion 这种格式如何弄?ZHXZHX: 网址: https://youthce.com/B-a7352566cc3c4141891195bc18c30af0 想像上面的图片格式一样,利用 notion 制作一个简单的网页书签整理,替代书签同步功能,顺便整合一些不常用的书签。 但原网址限制了模板复制,不能套用。 刚接触 notion,一开始以为是 table,上网搜索一番,找不到方法…
请教 chrome 播放音视频突然没有声音了怎么办futou:平台: win10 1909 chrome: 正式版 85.0.xxx 64bit chrome 昨天开始突然没有声音,网上搜索发现很多相似情况。 未静音,edge 浏览器及其它软件有声音。 重启 windows audio 服务后可以短时间内解决 chrome 的问题,换个视频就又不行了。 重置 setting 、更新和重装解决不了 chrom…
请教 移动端 web 页面如何导出为 pdfsybb:有个移动端的 web 项目,想把页面输出成一个 pdf 文件, 来实现打印页面到 A4 纸我了解的是 pc 端的网页可以直接用 window.print()方法输出页面的 pdf, 但是移动端的话就没有这个方法了请教一下各位有什么方案可行呢
请教 watchOS 7 的 GMT 表盘怎么用ccming:如何看第二时间,如何设置第二时间ashong:四角位置可选 ccming:@ashong 我问的不是这个 ccming:@ashong 中间的表盘是模拟一种机械表,有内圈(本地时间)外圈(第二时间)