I decided to make a small project which I will cover with tests as much as I can. I'm using CLion (which uses CMake) and Catch library for testing.
The problem is that I'm getting undefined reference to TestClass::add
method while I run test class.
Here is my setup (it's a dummy one since I wanted to make sure if everything works):
TestClass.h
#ifndef LLL_TESTCLASS_H
#define LLL_TESTCLASS_H
class TestClass {
public:
int add(int a, int b);
};
#endif //LLL_TESTCLASS_H
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})
Aucun commentaire:
Enregistrer un commentaire