
xtest
C++ testing framework inspired by googletest
Explore the docs »
Wiki · Report Bug · Request Feature
Contents
xtest
xtest is a C++ testing framework inspired by gtest
. This is just a minimal implementation of a C++ unit testing framework which gives all the required facilities for unit testing a software without going template crazy and causing compilation issues.
Consider installing xtest
from the most stable branch stable.
Commence
To download and install library xtest in your system follow the following steps.
Prerequisites
You must have a g++ 9.3.0
or greater version with a cmake
version 3.16.3
or higher installed in your system.
Ubuntu
Step 1: Install gcc
sudo apt update
sudo apt install build-essential
If this is the first time you are installing g++
then you may also want to install the manual pages about using GNU/Linux for development.
sudo apt install manpages-dev
Verify that the compiler is installed.
g++ --version
and it should print,
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
In the above output ubuntu1~20.04 is my version, yours may be different.
Step 2: Install cmake
-
Uninstall the default
cmake
version provided by Ubuntu's package manager and configuration by using:sudo apt remove --purge --auto-remove cmake
OR:
sudo apt purge --auto-remove cmake
This step is crucial if you have a old version of
cmake
installed in your system. -
Prepare for installation.
sudo apt update sudo apt install -y software-properties-common lsb-release sudo apt clean all
-
Obtain a copy of kitware's signing key.
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
-
Add kitware's repository to your sources list for
Ubuntu Focal Fossa (20.04)
,Ubuntu Bionic Beaver (18.04)
andUbuntu Xenial Xerus (16.04)
.sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
-
As an optional step it is recommended that we also install the kitware-archive-keyring package to ensure that Kitware's keyring stays up to date as they rotate their keys.
sudo apt update sudo apt install kitware-archive-keyring sudo rm /etc/apt/trusted.gpg.d/kitware.gpg
-
Finally we can update and install the cmake package.
sudo apt update sudo apt install cmake
Installation
Clone the repository.
git clone https://github.com/joshiayush/xtest.git
Build xtest
Next step is to build xtest
as a shared library using our build system cmake
.
cmake -B build/ -S .
cd build
make install
This will build xtest
library as libxtest.so
file inside the build
directory. Now as the next step you have to create a symbolic link of libxtest.so
in /usr/lib/
directory,
sudo ln -s /build/libxtest.so /usr/lib/libxtest.so
Now create symbolic link for the header files inside /usr/include/C++/9
inside xtest
,
sudo mkdir /usr/include/C++/9/xtest
sudo ln -s /include/** /usr/include/C++/9/xtest
Now you are all set.
Build samples
To build samples,
cmake -B build/ -S . -DBUILD_SAMPLES:BOOL=ON
cd build
make install
Now run the samples
,
./samples/factorial/factorial # Runs the factorial unit test samples binary
./samples/isprime/isprime # Runs the isprime unit test samples binary
Usage
Testing a custom function that returns the sqaure of a given number.
#include <xtest/xtest.hh>
double square(int n) {
return n*n;
}
TEST(TestSquare, TestWithPositiveNumber) {
EXPECT_EQ(square(10), 100);
}
int32_t main(int32_t argc, char** argv) {
::xtest::InitXTest(&argc, argv);
return RUN_ALL_TESTS();
}
Now compile the file and link the libxtest.so
file with it:
g++ -lxtest square_test.cc -o square_test
For more information on usage see our wiki.
Contribution
Contributions are what makes the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement", "bug", or "documentation". Don't forget to give the project a star! Thanks again!
Project xtest is hosted on GitHub. If you want to contribute changes please make sure to read the CONTRIBUTING.md
file. You can also contribute changes to the CONTRIBUTING.md
file itself.
License
Distributed under the BSD 3-Clause License. See LICENSE
for more information. Please do not use project xtest if you have any issue with the BSD 3-Clause License.
Developers
Acknowledgments
A big thanks goes to the following resources who have helped in the development of project xtest.