I want to get started on Unit Testing in C++ (pure C++, not .NET), since I have never done it before. Always used assert and cout.
So far, the only good Question with detailed answers, I have found is https://stackoverflow.com/questions/13699/choosing-a-c-unit-testing-tool-framework, but it is dated to 2008.
I would like to hear some opinions about currently available C++ Unit Testing compatible with Visual Studio 2012. What are their Cons and Pros ? How easy/hard to learn them(i.e availability of learning materials) ? How Popular they are ? Are they being actively developed, supported ?
There are several frameworks that I am aware of: Google's Testing Framework, Boost Testing Lib.
(Also, in addition to Visual Studio, I use Intel Parallel Studio XE 2013, primarily for static analysis)
At the moment we only use the unit testing functionality which comes with VS12 (Premium). We also tested other Frameworks (e.g. NUnit), but for now VS12 testing suits well.
I use TUT unit testing framework: http://tut-framework.sourceforge.net/
Related
I want to start writing unit test cases using the Microsoft Fakes framework in Visual Studio 2013 Professional.
Please advise on how I can achieve this.
Fakes is only available with VS Ultimate and Premium. There is no installer that will allow you add the fakes functionality to VSPro
http://www.visualstudio.com/products/compare-visual-studio-products-vs
Although Fakes is only available to VS Ultimate/Enterprise users, its predecessor, Moles, is available for free.
They're largely the same, except Fakes uses a different naming scheme, and plays slightly better with non-MSTest testing frameworks.
There is also an open-source alternative named Prig which I know nothing about.
I'm doing some research on Unit Testing and most of the questions I see on Stack Overflow about NUnit are at least a year old now. Are you using any new tools for Unit Testing that are available via Visual Studio 2010 and .NET 4.0? Please share any new technologies that you are aware of. Thanks!
MSTest is built into Visual Studio 2010 and we've been using it at my companies since VS 2008. It is robust and simple unit testing framework and you don't have to run anything third-party.
Just create a new unit test project and you should be off to the races.
That said, I know a lot of people who use NUnit and are perfectly happy with it.
NUnit is still one of the most popular unit testing frameworks out there. MsTest is also a popular framework because it is included by default with VS. If you want a framework that does its own thing you could look at XUnit. One I have used in the past and enjoyed is MbUnit.
In my opinion I would spend more time into looking into your mocking framework. They differ far more than testing frameworks. Some of the more popular are Moq, NMock, Easy Mock, Rhino Mocks, if you want free. For paid you have TypeMock and Just Mock. My current preference would be Moq because of the more fluent typing.
One of the recent testing-related cool things that came from Microsoft is Pex. Lifted from the project page:
Pex automatically generates test
suites with high code coverage. Right
from the Visual Studio code editor,
Pex finds interesting input-output
values of your methods, which you can
save as a small test suite with high
code coverage. Microsoft Pex is a
Visual Studio add-in for testing .NET
Framework applications.
Definitely worth checking.
Does any one know if I can test native code in VS Test 2010?
As of VS2010, native C++ unit testing is not directly supported by Visual Studio. See MSDN, specifically:
You cannot have test projects with unit tests that use unmanaged C++.
You can still do native C++ unit testing with Visual Studio, but it won't be as integrated as other VS features. See this SO answer for a number of native unit testing frameworks and libraries. I have not used any of those, so I cannot give any guidance there.
I would bite the bullet, download Boost and get the test suite compiled. Once you get into it, it's as easy as VS tests.
It seems to be mainly tailored to .net code.
Only managed C++ (/clr:safe): Unit Tests and C++
You could use WinUnit (if you are not already): Simplified Unit Testing for Native C++ Applications
You can't get the slick attribute-driven features of managed test frameworks with native unit test frameworks. If you want a graphical runner which lets you select individual tests or fixtures within Visual Studio, grab the excellent, free Visual Assert. It supports both the cfix framework and (via cfix) a WinUnit compatibility mode. I've been happily using it for several months now in both 2008 and 2010.
I'm new to both unit testing and Visual Studio 2010 (just upgraded from 2008). I'm interested in using VS2010's new built-in unit testing tools, but would like to get the lay of the land first. I haven't been able to find any resources or tutorials on unit testing with VS2010 specifically - has anyone found a good walk-through?
I'm also open to persuasion that we should stick with NUnit or the like, if anyone knows a reason to avoid the built-in tools.
PEX and PEX Tutorial
Here's a Channel9 video titled "TestDriven Development with Visual Studio 2010".
She goes through the basics of the Test Project, and it seems a good intro, Channel9-style!
Aside:
This is vintage 2008 material, and the GUI of Visual Studio doesn't look like RTM. You can see though, when she selects text, that it appears to highlight ala 2010.
I prefer using open source tools such as NUnit, the reason is, if you use the built-in testing tools in your projects, those will not be available to developers running express versions of Visual Studio. This might not be a good enough reason for you but it is for me, specially when you work with .NET open source projects.
Good luck!