我一直在寻找答案,但我没有找到答案。问题是,我需要为我用 C 编写的程序做一些测试用例。问题是,一些函数接受用户输入,这使我的测试用例等待输入,这不是我想要的。
这是我的测试用例之一:
void test_is_location_free() {
Storage test_storage = new_storage();
Item test_item;
test_storage->inventory[5] = test_item;
test_storage->inventory[5].loc.shelf = 'A';
test_storage->inventory[5].loc.place = 1;
CU_ASSERT(!is_location_free(test_storage, test_item, 'A', 1));
}
这是有效的,因为 is_location_free() 将返回 false,但在函数内部,我有另一个函数会不断询问用户新的输入,直到所选位置空闲。
这是它在终端中的样子,它将等待新的用户输入货架:
Suite: HELPER FUNCTIONS
Test: compare_char() ...passed
Test: first_empty_position() ...passed
Test: is_location_free() ...Location not empty, try again!
Shelf:
有没有办法完全忽略所有用户输入,或者定义我的测试用例将使用的未来用户输入?
谢谢!