Sign in to follow this  

Visual Studio 2015 C++ Unit Testing.

This topic is 707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, can anyone recommend a good book/tutorial that covers Unit Testing C++ code in Visual Studio 2015?

I've tried reading the online documentation for it, and whilst it appears very simple and straight forward, on the surface, I suspect there is more to it then initially meets the eye, and am finding said documentation somewhat impenetrable.

I am an experienced C++ programmer that has been out of work for some time (around 10 years or so) due to ill health and am looking to get back into dabbling in 3D Graphics and Game programming to keep my skills sharpened. But I last touched any code or Visual Studio about 5 years ago though, so things have changed!

Thanks in advance.

Scott Hill.

Share this post


Link to post
Share on other sites
That's a pretty broad area.

Are you looking more for articles about how to write unit tests, what goes in them, and how they work?

Or are you looking more for articles about VS2015's test runners, using the environment, and working with results?

Share this post


Link to post
Share on other sites

More information on how to write C++ Unit Tests using the features built in to VS2015.

 

Although you could use the Microsoft Unit Testing Framework, I would recommend against choosing that route, as it would bind you to one vendor and make your unit tests unusable on other platforms. You don't even gain anything like IntelliTest for partially automated test generation, as that is for .NET only.

 

I would rather have a look at other, cross platform unit testing frameworks such as:

  1. Google Test
  2. Boost.Test
  3. Catch

There are plenty others. Out of the previous list, you might like catch as it is only a single header, so no headaches with building a medium or large library first.

Share this post


Link to post
Share on other sites

 

More information on how to write C++ Unit Tests using the features built in to VS2015.

 

Although you could use the Microsoft Unit Testing Framework, I would recommend against choosing that route, as it would bind you to one vendor and make your unit tests unusable on other platforms. You don't even gain anything like IntelliTest for partially automated test generation, as that is for .NET only.

 

I would rather have a look at other, cross platform unit testing frameworks such as:

  1. Google Test
  2. Boost.Test
  3. Catch

There are plenty others. Out of the previous list, you might like catch as it is only a single header, so no headaches with building a medium or large library first.

 

Thanks for the suggestions.

However, I am not looking for a cross-platform unit testing framework.

I am looking to gain a better understanding, than I can get from the online documentation, of the C++ unit testing framework the comes integrated with Visual Studio 2015.

Basically, I'm looking for a "How to use the C++ Unit Testing Framework in Visual Studio 2015".

Share this post


Link to post
Share on other sites

One bit of advice around unit tests, it is a technique that can take a while to get used to. The principles are simple enough but if your code is not written with test-ability in mind you will find you have tests that require massive build up and tear down code. It is worth the investment but at first can be an uphill climb.

 

For tools... If the C++ version is as good as the C# one then I recommend you do yourself a favor and get ReSharper C++. I have not used the C++ one but long time user of the C# version. It makes running all the tests in a solution or individual tests, including debug, so simple. That along with all the other things ReSharper brings to the table.

 

If your project is open source and been running 3 months you can get free as well if not its not too pricey for individual devs.

 

Either way there is 30 day trial to see if you like.

Share this post


Link to post
Share on other sites

Personally, I would try to lead you down the path of GoogleTest and GoogleMock.  They play well together which is better than most C++ test/mock frameworks out there.  

 

The really cool thing here is that they are/were in NuGet and there is a VS extension to run your tests.

 

NuGet:

https://www.nuget.org/packages/gtest/

 

VS Google Test Runner:

https://visualstudiogallery.msdn.microsoft.com/9dd47c21-97a6-4369-b326-c562678066f0

 

In terms of documentation, I recommend GoogleTests documentation.  They really went to some great pains to document the hell outta it, https://github.com/google/googletest/tree/master/googletest/docs

 

Ping me if you need some examples or perhaps even a few minute screencast and I gladly throw something together.

Share this post


Link to post
Share on other sites

I am using Microsoft's unit testing framework for both C++ and C#.

 

As others have pointed, it's not cross-platform so you have to think seriously about it, but if you don't care, I think it works better than Google's test framework, and it has first class support and integration in Visual Studio which I like. It just works like a charm and I like it.

 

But again, the platform lock is a hefty price to pay, and Linux and Mac are getting more and more relevant, so think about it.

Share this post


Link to post
Share on other sites

This topic is 707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this