https://github.com/christopherbate/quicktestcpp
QuickTestCPP - A lightweight C++ unit testing header library.
https://github.com/christopherbate/quicktestcpp
cpp11 header-library simple unit-testing
Last synced: 7 months ago
JSON representation
QuickTestCPP - A lightweight C++ unit testing header library.
- Host: GitHub
- URL: https://github.com/christopherbate/quicktestcpp
- Owner: christopherbate
- License: unlicense
- Created: 2018-10-13T18:37:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-10T22:10:55.000Z (over 5 years ago)
- Last Synced: 2025-02-09T20:36:22.589Z (8 months ago)
- Topics: cpp11, header-library, simple, unit-testing
- Language: C++
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
## QuickTestCPP
QuickTestCPP is a lightweight header-only tool for quickly developing unit tests in C++ (11). I created this to for projects that requried unit tests, but for whatever reason bringing in a larger testing library was out of the question. I modeled the terminology after Google Tests's terminology. A "test" is an individual test, and a "test case" is a set of tests. We keep the syntax relatively lightweight by leveraging C++ lambda functions. The whole idea is relatively simple, as shown in the below examples. Create the tests with lambda functions, and return true or 1 on success, 0 or false on failure. At the end, call the print summary for a description.
## Example usage.
~~~~
#include "QuickTestCPP.h"
#include
[other includes]int main(int argc, char **argv)
{
std::cout << "Starting tests." << std::endl;TestRunner::GetRunner()->AddTest(
"HTTP Request Parsing",
"Must parse protocol version",
[]() {
string hdr = "GET /Protocols/rfc1945/rfc1945 HTTP/1.1";
HTTPRequest request(hdr);
if (request.GetProtocol() != "HTTP/1.1")
return 0;
return 1;
});TestRunner::GetRunner()->AddTest(
"HTTP Request Parsing",
"Must parse url",
[]() {
string hdr = "GET /Protocols/rfc1945/rfc1945 HTTP/1.1";
HTTPRequest request(hdr);
if (request.GetUrl() != "/Protocols/rfc1945/rfc1945")
return 0;
return 1;
});TestRunner::GetRunner()->AddTest(
"TCP Socket Creation",
"Must be able to accept connections",
[]() {
TCPSocket socket;bool res = socket.CreateSocket("8080");
if (!res)
{
std::cerr << "Failed to create list socket." << endl;
return 0;
}socket.Listen();
TCPSocket connSocket;
res = connSocket.CreateSocket("localhost", "8080");
if (!res)
{
std::cerr << "Failed to create active socket." << endl;
return 0;
}TCPSocket *connection = socket.Accept();
if(connection == NULL){
std::cerr <<"Did not accept connection"<Run();TestRunner::GetRunner()->PrintSummary();
return TestRunner::GetRunner()->GetRetCode();
}
~~~~