I decided to make a small project, which I will tell with the help of tests, as far as I can. I use CLION (which uses CMake) and the Catch library for testing.
The problem is that I get the method undefined reference to TestClass::addwhile running the test class.
Here is my setup (this is dummy as I wanted to make sure everything works):
TestClass.h
#ifndef LLL_TESTCLASS_H
#define LLL_TESTCLASS_H
class TestClass {
public:
int add(int a, int b);
};
#endif
Testclass.cpp
#include "TestClass.h"
int TestClass::add(int a, int b) {
return a + b;
}
test.cpp - file with tests
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "../src/TestClass.h"
TEST_CASE("addition") {
TestClass testClass;
REQUIRE(testClass.add(2,3) == 5);
REQUIRE(testClass.add(-1, 1) == 0);
REQUIRE(testClass.add(2, 4) == 1);
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(LLL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(LIB_DIR "lib")
include_directories(${LIB_DIR}/Catch)
include_directories(${LIB_DIR}/Eigen)
set(SRC_DIR src)
set(SOURCE_FILES ${SRC_DIR}/main.cpp src/TestClass.h src/TestClass.cpp)
add_executable(LLL ${SOURCE_FILES})
set(TEST_DIR test)
set(TEST_FILES ${TEST_DIR}/test.cpp)
add_executable(LLL_TEST ${TEST_FILES})
source
share