GithubHelp home page GithubHelp logo

panquesito7 / xtest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshiayush/xtest

0.0 1.0 0.0 215 KB

xtest is a C++ testing framework inspired by googletest.

License: BSD 3-Clause "New" or "Revised" License

C++ 95.93% CMake 4.07%

xtest's Introduction

Contributors Forks Stargazers Issues LICENSE LinkedIn


Logo

xtest

C++ testing framework inspired by googletest
Explore the docs »

Wiki · Report Bug · Request Feature

Contents
  1. xtest
  2. Usage
  3. Contribution
  4. License
  5. Developers
  6. Acknowledgments

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

  1. 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.

  2. Prepare for installation.

    sudo apt update
    sudo apt install -y software-properties-common lsb-release
    sudo apt clean all
  3. 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
  4. Add kitware's repository to your sources list for Ubuntu Focal Fossa (20.04), Ubuntu Bionic Beaver (18.04) and Ubuntu Xenial Xerus (16.04).

    sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
  5. 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
  6. 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.

xtest's People

Contributors

joshiayush avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.