我使用CMake构建我的项目,并使用CTest(Fraemwork-Catch2)构建测试依赖项。在某些测试中,我需要实时检查KeyPress行为(无需REQUIERE(..)):
TEST_CASE("Test func"){
while(!sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
for(int key = sf::Keyboard::Key::A; key <= sf::Keyboard::Key::Z; key++){
if(sf::Keyboard::isKeyPressed(static_cast<sf::Keyboard::Key>(key)))
std::cout << key << '\n';
std::cout << key << '\n';
}
}
}
我依赖CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project (Tests)
add_executable(action_test Action/Action_test.cpp)
target_link_libraries(action_test sfml-graphics sfml-window sfml-system action)
enable_testing()
add_test(NAME Action_test COMMAND action_test)
构建后,我开始测试:
$ctest -V
但是它给我的输出速度很慢,但是如果我直接从二进制文件夹运行测试(没有CTest),输出速度就很棒!