Code Coverage Tool (Part 3)


This is the last part of code coverage tool, in this post we will see the open source code coverage tool,i.e. OpenCoverage which is light weight and totally free to use. Which will give almost all functionalities as similar to third party code coverage tool (Ncoder and DotCover)

NCover Code Coverage Tool
DotCover Coverage Tool

How to use OpenCover tool?

Step 1: Create some demo unit test case in visual studio. I have written some dummy unit test case as given below

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestCase_Sample
{
    [TestClass]
    public class UnitTestCaseDemo
    {
        [TestMethod]
        public void AdditionOfTwoNum()
        {
            var a = 0;
            var b = 0;
            if (a!=0 && b!=0)
            {
                var result = a + b;
                Assert.AreEqual(30, result);
            }
            else
            {
                var result = a + b;
                Assert.AreEqual(0, result);
            }
        }

        [TestMethod]
        public void SubstractionOfTwoNum()
        {
            var a = 20;
            var b = 10;
            var result = a - b;
            Assert.AreEqual(10, result);
        }

        [TestMethod]
        public void MultiplicationOfTwoNum()
        {
            var a = 20;
            var b = 10;
            var result = a * b;
            Assert.AreEqual(200, result);
        }

        [TestMethod]
        public void DivisionOfTwo_Num()
        {
            var a = 20;
            var b = 10;
            var result = a / b;
            Assert.AreEqual(2, result);
        }

        [TestMethod]
        public void Addition_Of_ThreeNum()
        {
            var a = 10;
            var b = 20;
            var c = 30;
            var result = a + b + c;
            Assert.AreEqual(60, result);
        }

        [TestMethod]
        [ExpectedException(typeof(DivideByZeroException))]
        public void Test()
        {
            int i = 10, j = 0;
            int x;
            x = i / j;
        }
       
    }
}

Step 2: Download the OpenCover UI from Microsoft store, from the given below URL

https://marketplace.visualstudio.com/items?itemName=jamdagni86.OpenCoverUI

In Visual Studio Tab will show like this

Step 3: Right click on solution explorer and click on Manage NuGet Packages and Install the OpenCover and ReportGenerator in your application as given below

Step 4: Go to Visual studio Tool ->> Options ->> OpenCoverUI Options then select the OpenCover.Console.exe from your application.

Step 5: Go to OpenCover tool of Visual Studio and Select OpenCover Test Explorer and select the test cases to be run like given below Image

Now we will get output like given below

In the above result it is showing that how much code has been covered in which test case.

If you have to fix the problem then just double click on given method, you will see the code like this given below image

This indicate that below code branch has not been executed. So we have to write the other unit test case to cover above code.

How to get the report as third party control as similar to Ncover and DotCover

For getting the report in user friendly manner we have to take help of Report Generator Tool.
For that we have to create the .bat file, which will generate the report in given folder.

Firstly create the notepad file keep this syntax as given below

"C:\Source\Test \packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\mstest.exe" -targetargs:"/noisolation /testcontainer:\"C:\Source\Test \Test\bin\Debug\Test.dll\" /resultsfile:C:\Reports\MSTest\.trx" -mergebyhash -output:C:\Reports\MSTest\projectCoverageReport.xml


"C:\Source\Test \packages\ReportGenerator.2.5.2\tools\ReportGenerator.exe" -reports:"C:\Reports\MSTest\projectCoverageReport.xml" -targetdir:"C:\Reports\CodeCoverage"

Now save the file as .bat extension and run the bat file.

Note: Before running the bat file, please create the Reports\CodeCoverage and MSTest directory in C folder.

Now go to the CodeCoverage folder and see the report after clicking on Index.html file like as given below

In the above tools compare we show that OpenCover contains almost all the major features which contains all the paid version tools and it is very light weight and flexible to use in any project.

Comparison between all the Tools

How to set up the last page read on adobe pdf reader


if you are reading some eBooks using adobe pdf reader, you have completed some page like 20 or 30 in one days. Again if you have to read after few days then if you will open the same book, then it will open from first page, It is very horrible experience.

Now you can fix this problem like this

Step 1: Go to Edit Menu

Step 2: Click on Preferences in your Adobe PDF Reader

Step 3: Select Document tab and check the “Restore last view setting when reopening documents.”

pdf-reader

How to use Corflags tool of Visual Studio to check 32/64 bit of dll ?


Hi

Corflags is the inbuilt tool of Visual Studio which is used to find out the type of .dll i.e 32 bit, 64 bit or any CPU. This tool is available in Visual studio 2005 onward. i.e. VS 2005/2008/2010/2013

These are the following steps to check in Visual Studio

Step1 : Go to visual Studio command prompt like this

Step1

Step 2: Make Sure that Corflags is working in your system

Type the Corflags in Command Prompt like this

Step2

Note: if this syntax is not working then there is some problem in Environment Variable of the System
You can fix this issue like this post
http://helpdeskgeek.com/how-to/fix-not-recognized-as-an-internal-or-external-command/

Step 3: Go to the file Location of DLL and type the syntax like this in below image
Corflags AjaxToolKit.dll

Corflag11

This is the short summary to determine the type of dll

Any CPU: PE = PE32 and 32BIT = 0
x86 bit: PE = PE32 and 32BIT = 1
64-bit: PE = PE32+ and 32BIT = 0

I hope this will help to some body.

Code Cleanup free tool for Visual studio 2010/12


Hi

Recently i was doing code cleanup of my project. I was searching some tool for this work then i got very nice tool. It is really very useful tool for developer. You also just try it.

You can download from here

http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/

You can read the documentation from here

http://www.codemaid.net/documentation/#reorganizing

I hope it will help to other developers.

Free eBook on Visual Studio 2012 from Telerik


Hi

Here is the excellent free eBook on Visual Studio 2012 from Telerik publication. Here you will learn all the new features of VS 2012 in very easy ways. It is completely free to download.

Free eBook on VS 2012 from Telerik download link

I hope you will enjoy while reading this book.

How to make cross browser compatibility of website?


Hi
Some many time, while developing web based project, It will look proper on one browser,but it doesn’t look proper on other browser. I had faced this problem so many time.

Here is some free tools which will help to check the XHTML and CSS standards.

If we don’t follow this standard then it will not look proper on all browser.

To validate HTML and XHTML
http://validator.w3.org/

To validate CSS
http://jigsaw.w3.org/css-validator/

Free web Template