To enable this, the project’s main CMakeLists.txt file must contain the following directive: enable_testing(). It can be called from the command line of the project’s build directory or from Qt Creator under the “Tools” menu. If the project is configured correctly, it’s invocation will trigger the running of all the project’s unit tests. The CMake build tool provides the program CTest as a means for unit testing. Creating a Unit Testing Project Infrastructure Using this module and illustrating it with a fun example hosted here, this blog describes how to create a Qt/ CMake project that easily supports Unit Testing. The Qt Test Module provides some tools that can facilitate this task. In the context of Graphic User Interfaces (GUI), developers are often confronted with having to write unit tests for what is typically validated by a human’s perception of the software’s look and feel. Test-driven Development (TDD), for instance, mandates that before a requirement is even implemented a corresponding test case must be written. Passed 0.Unit testing is becoming an essential part of the software implementation process. my_project/buildġ/1 Test #1: HelloTest.BasicAssertions. The CXX compiler identification is GNU 10.2.1 The C compiler identification is GNU 10.2.1 Now you can build and run your test: my_project$ cmake -S. Last two lines enable CMake’s test runner to discover the tests included in the You want to build ( hello_test), and links it to GoogleTest ( gtest_main). The above configuration enables testing in CMake, declares the C++ test binary ) include (GoogleTest ) gtest_discover_tests (hello_test ) With GoogleTest declared as a dependency, you can use GoogleTest code withinĪs an example, create a file named hello_ in your my_project Hash often to point to the latest version.įor more information about how to create CMakeLists.txt files, see the The Git commit hash of the GoogleTest version to use we recommend updating the The above configuration declares a dependency on GoogleTest which is downloadedįrom GitHub. ) # For Windows: Prevent overriding the parent project's compiler/linker settings set (gtest_force_shared_crt ON CACHE BOOL "" FORCE ) FetchContent_MakeAvailable (googletest ) You’ll use this file to set up your project and declare a dependency onįirst, create a directory for your project:Ĭmake_minimum_required (VERSION 3.14 ) project (my_project ) # GoogleTest requires at least C++14 set (CMAKE_CXX_STANDARD 14 ) set (CMAKE_CXX_STANDARD_REQUIRED ON ) include (FetchContent ) FetchContent_Declare ( Set up a projectĬMake uses a file named CMakeLists.txt to configure the build system for a Note: The terminal commands in this tutorial show a Unix shell prompt, but theĬommands work on the Windows command line as well. If you don’t already have CMake installed, see the See Supported Platforms for more information about platforms CMake and a compatible build tool for building the.A compatible C++ compiler that supports at least C++14.You’re using GoogleTest for the first time or need a refresher, we recommend This tutorial aims to get you up and running with GoogleTest using CMake.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |