Wiki
Clone wikicodetrainer / Creating a test
For this exercise, I will assume you followed Creating a new plugin and have the "tangent" plugin created and working.
Let's consider the following directory structure:
#!c++ --- C:\Code ----- CodeTrainer ----- CodeTrainerPlugins ----- gtest
If you go to the "C:\Code\CodeTrainerPlugins\unit_test" directory, you will notice the following structure:
#!c++ --- C:\Code\CodeTrainerPlugins\unit_test ----- sine.cc ----- util.cc ----- util.h ----- CMakeLists.txt ----- unit_test.vcxproj.user.in
Copy the file "sine.cc" to "tangent.cc" and modify it to look like this:
#!c++ #include "gtest/gtest.h" #include <string> #include "base/Interfaces.h" #include "util.h" class TestTangent: public ::testing::Test { protected: virtual void SetUp() { Test::SetUp(); pFunction = GetPluginFunction("plugins/functions/tangent.dll"); if (!pFunction) { ASSERT_EQ(1, 0); } } virtual void TearDown() { Test::TearDown(); } IFunction* pFunction; }; TEST_F(TestTangent, TestTangentOfZeroIsZero) { EXPECT_DOUBLE_EQ(0, pFunction->Evaluate(0)); }
Close all instances of Visual Studio, launch the buildall.bat and wait for the build to finish. After this, you can run "unit_test.exe" from the install directory and you can notice that there is also a unit test ran for "tangent" plugin.
Updated