cunit测试空隙功能
您好,我是 Cunit 测试和一般测试的新手。我找不到测试这个 void 函数的方法。想知道如何正确地做到这一点或如何重构它。 关于如何正确测试 void 函数有什么建议吗?谢谢。
void validate_arg(int argc, char *argv[], struct Statistics *stats) {
if (argc == 4 && strcmp(argv[2], "-G") == 0) {
FILE *file = fopen(argv[3], "w");
stop_prog(write_stats(file, stats), err1);
fclose(file);
}
free(stats);
}
我编写了 Cunit 测试,但我无法断言任何内容,因为它是空的,并且我无法测试要写入的文件是否已创建,因为它在 if 内被释放。
void test_validate_args_0(void) {
struct Stats *stats = malloc(sizeof(struct Stats));
char* argv[] = {"TEST", "dummy", "-G", NULL};
CU_ASSERT_EQUAL(validate_arg(4, argv, stats), 0);
free(stats);
}
Hi Im new to Cunit tests and testing in general. I cant find a way to test this void functon. Wondering how to properly do it or how to refactor it.
Any tips on how to properly test void functions? Thanks.
void validate_arg(int argc, char *argv[], struct Statistics *stats) {
if (argc == 4 && strcmp(argv[2], "-G") == 0) {
FILE *file = fopen(argv[3], "w");
stop_prog(write_stats(file, stats), err1);
fclose(file);
}
free(stats);
}
The Cunit test I wrote but I cant assert anything since its a void and I cant test if my file to write was created since since it gets deallocated inside the if.
void test_validate_args_0(void) {
struct Stats *stats = malloc(sizeof(struct Stats));
char* argv[] = {"TEST", "dummy", "-G", NULL};
CU_ASSERT_EQUAL(validate_arg(4, argv, stats), 0);
free(stats);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论