I'm new to unit testing and decided to use the Catch framework for c++ because it seemed easy to integrate with its one header file. However, I have a multifile binary search tree program (files are: main.cpp, Tree.h, Tree.hxx, TreeUnitTests.cpp, catch.hpp). I can only get my unit tests to run if I comment out my int main() function in main.cpp. I understand that it is conflicting with '#define CATCH_CONFIG_MAIN' declaration in my TreeUnitTests.cpp, but I cannot get the unit tests to run if I do not include that declaration. How can I get both to run without having to comment my main() every time I want to run the unit tests?
This is the header file I am using: https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp
And the Catch tutorial I found it on and used as a guide: https://github.com/philsquared/Catch/blob/master/docs/tutorial.md
Some relevant files for reference: main.cpp:
//******************* ASSN 01 QUESTION 02 **********************
#include "Tree.h"
#include <iostream>
using namespace std;
/*
int main()
{
//creating tree with "5" as root
Tree<int> tree(5);
tree.insert(2);
tree.insert(88);
tree.inorder();
cout << "does tree contain 2?: ";
cout << tree.find(2) << endl;
cout << "does tree contain 3?: ";
cout << tree.find(3) << endl;
Tree<int> copytree(tree);
cout << "copied original tree..." << endl;
copytree.preorder();
cout << "after deletion of 2:\n";
copytree.Delete(2);
copytree.postorder();
return 0;
}
*/
TreeUnitTests.cpp:
#include <iostream>
#include "Tree.h"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("Pass Tests")
{
REQUIRE(1 == 1);
}
TEST_CASE("Fail test")
{
REQUIRE(1 == 0);
}
(my tests are not real tests, only to verify that the Catch framework was working correctly. I guess you can say it's a meta test)