Friday 27 May 2016

Code Coverage Using Google Test for unmanaged code using Visual Studio

Folks I am back with a shout out. Today we are going to walk on creating a static library in Visual c++ and will use Google test to write unit test and perform code coverage.
In this small article I will be using a set of utilities
Visual studio 2013, Google Test Runner that integrate in Visual studio for easy discovery of gtest and the finally the Google test framework. I am writing this to get a quick revision if some day I walk back again to do it again.


The very first step was to download the tool shown above

I downloaded the gtest framework and compiled the library using the following setting



Once the library is ready I created a dummy static library to get some hands on testing and named it as Win32Project1 which simply had two functions sum and sub.



To start writing some Google test code I created a another C++ console based application and configured it with the settings to get code coverage by setting linker properties of the test project as


And advanced->profile as

Do you know that the above two settings will help me to get coverage of the api I am going to test in a while.
One these are set I created a dummy Gtest which is very basic and ran it using the test runner. Notice that I have to set of test written one from Microsoft unit testing other from google test setting applied before writing test was.

 
As the picture show sum is 100% covered however the sub is not covered as I have no test written for it in Google Tests.




2 comments:

  1. Hello, Atul Raina.

    Do you know how if this work on VS2015?

    Thanks.

    ReplyDelete
  2. In today's truly global https://geexstar.com/a-comprehensive-review-of-nordvpn-the-best-vpn/ industry, success is now more than ever dependent on software quality. A good quality product or service leads to satisfied and loyal customers. A business that compromises on quality loses customer loyalty in the long run. The challenge that most IT managers have is how to effectively test software applications on time and within budget while balancing resources? Under the right circumstances, "crowd sourcing" offers a rapid and cost-effective approach to software testing. Rigorous testing is particularly significant for mission critical applications because a formal approach, though a proven method for reducing defects in software, requires highly specialized talent that is unavailable in most organizations. Furthermore, formalized testing cannot be scaled to cover the scope of the complex software deployed most in the modern IT landscape. The massive adoption of the Agile software development methodology advocating shorter iterations of development brings testers closer to development process. With proliferation of web applications, software is deployed on the Internet and bugs become apparent very quickly. Set with a budgetary limit (testers are paid a certain rate per valid bugs found), 'crowd sourced' testing is a highly compelling innovation that can be used to complement existing test cycles.

    ReplyDelete

Apache Beam Learning In Java Tutorials

 Wow  https://youtu.be/9kGETU63rkc