xtd.tunit overview
This topic shows how to create a simple xtd.tunit project and how to run it from the command line, with Visual Studio Test Explorer or external tools.
For this we will use a simple test.
Sources
- src/unit_test1.cpp :
#include <xtd/xtd.tunit>
using namespace xtd::tunit;
namespace unit_test_project2 {
class test_class_(unit_test1) {
void test_method_(test_method1) {
assert::is_true(true);
}
void ignore_test_method_(test_method2) {
assert::is_true(true);
}
void test_method_(test_method3) {
assert::is_true(false);
}
};
class test_class_(unit_test2) {
void test_method_(test_method1) {
assert::is_true(true);
}
void test_method_(test_method2) {
assert::is_true(true);
}
};
}
- CMakeLists.txt :
cmake_minimum_required(VERSION 3.20)
# Project
project(unit_test_project2)
find_package(xtd REQUIRED)
add_sources(
src/unit_test1.cpp
)
target_type(TEST_APPLICATION)
# Install
install_component()
Console
You can execute your xtd.tunit project in command line.
On Windows
Run "Command prompt", go to the buid directory of the project (unit_test_project2\build\Debug
) and type the following line :
unit_test_project2
On macOS and Linux
Run "Terminal", go to the buid directory of the project (unit_test_project2/build/Debug
) and type the following line :
./unit_test_project2
Output
Options
You can use the following command line flags to control its behavior. Type unit_test_rpoject2 --help
for list the command line flags.
Output
Visual Studio Explorer
You can run your xtd.tunit project by using the Test Explorer window of Visual Studio 2019 or later.
For more information about using Test Explorer, see Run unit tests with Test Explorer.
Remarks
- Make sure that the Test Adapter for Google Test tool is installed. It should be installed by default.
tunit-gui
The tunit-gui tool (not ready yet, only a c# prototype exists for the moment), can run xtd.tunit project.
Other unit tests GUI tools
xtd.tunit is compatible with google-test (gtest). So any thirdparty unit tests GUI tool written for gtest can execute xtd.tunit project.
For example the gtest-runner tool can run your xtd.tunit project.
List of known IDE/tools compatible with xtd.tunit
List of known IDE/tools NOT compatible with xtd.tunit
- QtCreator : The "QtCreator Tools Tests" does not work because it analyzes the source files to detect Google Test macros like (
TEST
,GTEST_SUITE
, ...).
Remarks
- Other third party IDE / tools could also run xtd.tunit projects but have not been tested.
- If you have a working IDE/tool, feel free to make a pull request to update the list of compatible tools.
- If you have an IDE/tool that doesn't seem to be working, don't hesitate to ask for support.
Next step
See also