<--Back

Overview

Now that you've successfully build boot, it is finally time to use it in a project.

Overview of the Steps

  • Create an Eclipse project
  • Configure the project to use CppUTest
  • Configure the project to use Boost


Setting up Initial Project

  • Start Eclipse and create a new workspace. I'll use c:\workspaces\firstexample for my workspace.
  • Close the welcome screen.
  • Create a new C++ project (File:New:C++ Project).
  • Enter a name, I'll use CppUTestHasItsSmoke
  • Under Executable, select Hello World C++ Project
  • Click Finish.
  • Right-click on your project (CppUTestHasItsSmoke), select Run As:Local C++ Application
  • Notice the output in the console:
!!!Hello World!!!

Configuring the Project for CppUTest

  • Edit your project's properties (right-click, properties)
  • Select C/C++ Build:Settings

Include Directories

  • Under GCC C++ Compiler:Includes enter the include directory of CppUTest.
    • Click the page with the green plus.
    • Select File system...
    • Enter or search to the directory. For my install location, the directory is: C:\workspaces\CppUTest2_1\includes.

CppUTest Library

  • Under MinGW C++ Linker:Libraries, enter both a library path as well as a library
  • Under Libraries (-l), click on the page with a green plus
  • Enter the name of the library (minus "lib" and ".lib"): CppUTest

Library Path

  • Under Library search path (-L), click on the page with a green plus
  • Enter the directory where the library is located. On my machine it is C:\workspaces\CppUTest2_1\lib
  • Click OK

Update main

You won't notice any changes unless you use CppUTest.
  • CppUTest uses the main() to execute its tests. So update the file with main() (CppUTestHasItsSmoke.cpp):
#include <CppUTest/CommandLineTestRunner.h>
 
int main(int argc, char **argv) {
    return CommandLineTestRunner::RunAllTests(argc, argv);
}
  • You can run your program as a Local C++ Application again:
OK (0 tests, 0 ran, 0 checks, 0 ignored, 0 filtered out, 0 ms)

Alternative main()

If you'd like to see a list of tests and the time each takes to run, you can either:
  • Provide command-line arguments when you run the program in Eclipse
  • Use an updated main to make it happen every time:
#include <CppUTest/CommandLineTestRunner.h>
 
int main() {
    const char* args[] = { "", "-v" };
    return CommandLineTestRunner::RunAllTests(2, args);
}

<--Back

Configuring the Project to use Boost

  • Edit your project's properties (right-click, properties)
  • Select C/C++ Build:Settings
  • Under GCC C++ Compiler:Includes enter the include directory for boost.
    • Click the page with the green plus.
    • Select File system...
    • Enter or search to the directory. For my install location, the directory is: C:\workspaces\boost_1_43_0.
  • Under MinGW C++ Linker:Libraries, enter both a library path as well as a library (for this example, we'll use boost date_time).
    • Under Libraries (-l), click on the page with a green plus
    • Enter the name of the library (minus "lib" and ".lib"): boost_date_time-mgw44-mt-1_43
    • Under Library search path (-L), click on the page with a green plus
    • Enter the directory where the library is located. On my machine it is C:\workspaces\boost_1_43_0\stage\lib
  • Click OK
  • Verify these settings.
    • Create a new file: BoostDateTimeSmokeTest.cpp:
#include <boost/date_time/gregorian/gregorian.hpp>
 
#include <CppUTest/TestHarness.h>
 
TEST_GROUP(Dates) {
 
};
 
TEST(Dates, CanBeLinkedIn) {
  using namespace boost::gregorian;
  std::string s("2001-10-9");
  date d(from_simple_string(s));
}
  • Important: The CppUTest header files need to be included last.
  • Build and run your tests. You're really just checking that you can compile and link.

<--Back

<--Back