May 10th, 2017

Unit Testing and the Future: Announcing the Test Adapter for Google Test

Augustin Popa
Senior Product Manager

The Visual C++ team is always looking for ways to improve the Visual Studio experience for C++ developers, regardless of their preferred development workflow. This time the focus is on unit testing. While Visual Studio has shipped with a native C++ test framework for a number of releases along with testing tools in the IDE, we recognize that there are a variety of C++ unit testing frameworks out there that developers may choose. Last year, we put out a survey to learn more about C++ developers use native unit testing to find problems with their code. Several test frameworks popped up frequently, most notably Google Test, Boost.Test, and Catch.

As of today we are pleased to announce the Test Adapter for Google Test, a Visual Studio extension that enables Google Test support using the IDE’s existing testing tools in the Test Explorer window. For Enterprise users, the Code Coverage window can also be utilized to get an idea of how much of a codebase is actually being tested. It’s worth noting that Google Test is only the first framework we have been working on, and Boost.Test will be coming soon as well. In this blog post, we will concentrate on Google Test.

Test Explorer Passing Tests

Background on the Test Adapter for Google Test

One of the best things about the Visual Studio ecosystem is the community that diligently builds extensions to enhance the product beyond its original design. One such extension is the Google Test Adapter, an open source project led by Christian Soltenborn and Jonas Gefele. The Google Test Adapter uses the extensibility points of the Visual Studio Test Platform to enable Google Test support in the IDE, and the Test Adapter for Google Test we are announcing today is essentially a fork of that project produced in collaboration with the two authors that adds a number of additional enhancements.

When we decided we wanted to invest in Google Test support, given the popularity of Google Test in the C++ community, we realized that it made sense to build something on top of this great extension rather than start from scratch, and collaborate with the existing community around the adapter by contributing our own engineering resources to the task. We are committed to continuing the open source nature of this project, and our own fork of the adapter will in turn be open sourced soon. We are thankful for the amazing community that is improving Visual Studio and wanted to give a shoutout to Christian and Jonas for their hard work and support.

To learn more about how the Google Test Adapter from Christian and Jonas works, check out their documentation. Much of this also applies to the new Test Adapter for Google Test.

New Features

With that said, you may be wondering what is actually different in the new extension.

In our research on Google Test usage, we found that a common pain point was the challenge of having to acquire and build the Google Test framework manually, while configuring it to match the specifications of the code under test. We wanted to make it easy to get started with Google Test, so you can now go to Add > New Project > Visual C++ > Test, and choose Google Test to set up a new Google Test project quickly and easily. Creating a Google Test Project We also set up several NuGet packages (which ship with the extension) that contain prebuilt copies of the Google Test framework and which get automatically acquired when you complete project creation. After you select the “Google Test” project type, we just need a little additional information: Test Project Configuration for Google Test You can optionally specify a project you want to test (and we’ll add a reference to the project for you), or skip this and add a reference yourself later. To complete project creation, we just need to know if you want a static or dynamic copy of the Google Test library and if you prefer to link the C++ runtime libraries dynamically (most common) or statically.

The experience above is designed to help users get started with Google Test, but if you already have Google Test set up with an existing project, the adapter should still work (see limitations below though for exceptions to this). Existing users may want to try out the new item template for Google Test, accessible via Add > New Item: New Item Template for Google Test The item template creates a simple file with some basic asserts in your current project, while the project template creates that file in a new project (and links in the Google Test framework for you). Starting Asserts in Google Test

Limitations of the New Extension

While we are striving to support as many scenarios as possible, there are a number of important limitations of the current version of the Test Adapter for Google Test:

  1. The new extension is only compatible with Visual Studio 2017. We do not plan to add support for earlier versions of Visual Studio, but you are encouraged to try the original adapter if you are using Visual Studio 2012, 2013, or 2015.
  2. The Google Test framework NuGet packages are not yet present on nuget.org. We plan to address this along with the next release.
  3. The Test Adapter currently only supports Win32 applications.
  4. The Test Adapter does not yet work in Open Folder mode (including for CMake projects developed via Open Folder).
  5. The original Google Test Adapter now supports a newer, experimental test execution framework. This framework will only work in the new extension if Visual Studio 2015 is installed side-by-side with 2017. The default, non-experimental framework works just fine with just VS 2017 however.
  6. Visual Studio ships with a feature called DEBUG:FASTLINK that is on by default, to improve linking times during compilation. This feature is currently unsupported in the Test Adapter for Google Test. You can disable FASTLINK by doing the following:
    1. Right-click the project you want to test, choose Properties.
    2. Go to Linker > Debugging > Generate Debug Info.
    3. Change the value to /DEBUG:FULL.
    4. FASTLINK GTest Bug

    Your Input

    This announcement is only the beginning of our efforts to support Google Test users. We are always looking for feedback and any bugs that you may find. If you encounter any issues with the adapter, please file a report on Developer Community.

    Download the Test Adapter for Google Test

Category
C++

Author

Augustin Popa
Senior Product Manager

Product manager on the Microsoft C++ team, currently working on vcpkg.

0 comments

Discussion are closed.