Monday, October 14, 2013

Using VS2012 and Google Test - Getting Started #1

I recently helped teach a class on Unit Level Testing using GoogleTest and VS2012. It was not a trivial as I thought it would be. But once I figured out some tricks to get everything running it works great. This blog and video is the first in a series of posts that will show how to effectively perform Unit level testing using GoogleTest and VS2012.

Setup GoogleTest in VS2012

  • Download googletest https://code.google.com/p/googletest/downloads , and extract to a directory:
  • Create a new project.
    • Right-mouse click on the Solution, and Add->New Project
    • Name the project googletest
    • Create a new project of static library: Add->New Project->Win32 Project->Static Library; Uncheck “precompiled header”
  • Compile googletest into a library.
    • Add include path , /include
    • Add source file /src/gtest-all.cc and gtest_main.cc
    • Change the pre-processor rules to include the definition. Project->Properties->C/C++->Preprocessor->Definitions Add _VARIADIC_MAX=10 (warning! Make sure not to have spaces in this definition)
    • Build the Project (F7)
  • Add a unit level test Project
    • Right-mouse click on the Solutuion, and Add->New Project
    • Create a new “Win32 Project-> Console application” project; Call it BitCoinTest; Uncheck “precompile header”.
    • Add include path and References…->Add Reference check both Bitcoin and googletest
    • Change the pre-processor rules to include the definition _VARIADIC_MAX=10.
    • Right-click on the project, and “Set as StartUp Project”
  • Build the solution
  • Run the default Project (Ctl-F5)
Look for the next blog GoogleTest and VS2012 - Writing you first Test Cases.

No comments:

Post a Comment