How to configure Visual Studio with Nunit Testing Framework


As we know that Nunit is testing framework which is widely used in .net community. It is open source and free to use. So in this post we will see how to configure the Nunit with Visual studio. Here i have used Visual Studio 2015.

There are the simple steps to configure the visual studio for Nunit Testing Framework.

Step 1: Open the visual studio –> Go to Tool Menu –> Extension and updates –>Select Nunit VS Templates and Nunit 3 Test Adapter

Step 2: Install the both plugin as shown below image

Step 3: Open the visual Studio and create new Test Unit Project like this

Step 4: Write some simple unit test case and click on Run All unit test as given below image.

Now no need to attach the dll into Nunit Software UI, we can run the unit test case in Visual studio Test Explorer as given above image.

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

Code Coverage Tool (Part 2)


Hi,

Before reading this post, please go through my previous article what is the code coverage tool

In this post we will see one of famous tool i.e. DotCover Code Coverage

It is the JetBrains Code coverage tools.It is paid version tool. It has the following features
1. Continuous unit testing
2. Code highlighter
3. Hot spot feature for breaking code.
4. Save code coverage report in HTML,XML and Json format

For download the trail version of this tool, you ca download from this URL

https://www.jetbrains.com/dotcover/download/

Before using this tool you have to also download and install re-sharper Tool.

If you have installed the tool successfully then you will get the resharper Menu in Visual Studio and from there you can select the Cover unit test case. You can also right click solution explorer and select the Cover Unit Tests and click on it like given below image

It will show the result like this

In the above image, it is showing which method has how much the code coverage.

It has the different type of save report options like HTML,Json and XML format

Example of HTML format Report

Example of JSON format Report

Example of XML format Report

Example of Json format Report

using the above report we can easily find out the uncovered test case in our application.

What is the code coverage tool ? (Part1)


Code coverage is the process of doing analysis in C# unit test code to find out which block or statement of code is executed or not.

The basic code coverage criteria are

1. Function coverage
2. Statement coverage
3. Branch Coverage
4.Conditional Coverage

There are so many tools available for this task

1. Visual Studio code coverage (Only in enterprise edition)
2. NCover
3. JetBrains dotCover
4. OpenCover
5. NCrunch
6. NDepend

I had gone through the few important code coverage tool

1.Visual Studio code coverage (Only in enterprise edition)

>> In visual studio enterprise edition default code coverage tool will be there. Since i am not using the enterprise version, I did not do deep on analysis on this tool. If you are using the enterprise edition you can go through the below URL

https://msdn.microsoft.com/en-IN/library/dd537628.aspx

2. NCover Code Coverage
>> Ncover is third party tool for visual studio.It is not the free tool. For this we have to download the software from given below URL

http://www.ncover.com/products/desktop

This tool is very straight forward to use. Firstly we have to install the tool then we will get the Ncover Menu in visual Studio.
Click on Ncover Code Coverage then you will get the Ncover Test Runner. It will load all the test case written in your application

Here i have written the test code like this

In the above test method, it will run only else condition so we are not testing the code of if condition. So if we will run the NCover tool it will show covered code as green and not covered code as red as given in above image.

It helps to find out the uncovered code in test application. This tool has also option to view the result on Desktop. It has also option to download the report in different format like html,Json and XML.

Posted in Tools. 1 Comment »

What is the batch file ?


Batch file is the file, which contains the collection command which should to be executed by command prompt. Batch file make user life more easier.

If user will click on batch file all the set of dos command statement will be executed. Batch file is also know as .bat extension file.

How to create the batch file ?

We can create the simple batch like this steps

Step 1 : Open the notepad file

Step 2 : Type this code in batch file

@echo off
echo Hello this a test batch file
pause
dir c:\windows
pause

Note: Here echo is used to display the message in Dos prompt and pause is used to hold the screen

Step 3: Save the file as .bat extension like this

Step 4: Double click on Test.bat file, you will get the output like given below

Summary:
In the above sample we saw that without writing the code in command prompt we can execute some set of command.

.Net Framework basic Concepts


If you are new to .net technology or even though you are working with .net technology, but you are not knowing the basic of .net technology then this article will help you to understand the all basic concept of .net technology.

If you are attaining any interview and you are not knowing the basic of .net framework then obviously they will reject you. So it is very important to understand the basis concept of .net.


So what is the .net Framework??

.net framework is the software which is developed by Microsoft for creating different type of application software.

What is the platforms?

>> Platform is the set of resource which will help to perform some particular task like Railways platforms will provide the set of resource to come the passenger and travel from source to destination location. It provide all type of facilities for passenger and train. For train, it will also provide the electricity, water, signal, platform number to halt. These all are the essential resource to keep the train running.

Is the .net can called as platform?

>> Yes we can call it as platform since it will provide all suitable environment to run any .net application.

Is the .net is platform independent?

Initially it was not a platform independent. It was developed to work only on window OS. But now it is the platform independent. It will work on all type of environment like window, Mac, Linux etc.

What are the main component of .Net Framework?

Main component of .net Framework is CLR, CTS, CLS and FCL
CLR (Common Language Runtime)
CTS (Common Type System)
CLS (Common Language Specification)
FCL (Framework Class Library)

net_fw

What is the CLR?

CLR is the common language runtime. It is the heart of .net framework. It performs the following task
1. Garbage collection
2. Code access security
3. Code verification
4. IL to Native code.

What is the CLS ?

CLS is the Common Language Specification. It is the set of rules and guideline to make any language to be execute on .Net Framework.

What is the CTS?

CTS is the Common Type System. It makes ensure that all data type defined in two language get compiled to common data type. It makes the smooth communication between all .net aware languages.

What is the FCL?

FCL is the framework class library. It is collection of reusable classes, interfaces and Value type. It is common for all .net aware languages. It is also called as base class library.

What is the garbage collector?

It is the process of cleaning the unused memory from the application. But it doesn’t clean unmanaged objects. Before .net there were not the concept of garbage collection in vb 6. Developer has to manually write the code for cleaning the unused memory from application.

Garbage collector process happen in 3 generations. Generation define the age of object
a. Generation 0
b. Generation 1
c. Generation 2

Generation 0: When the application create the fresh objects they are marked as Generation 0.

Generation 1: When the Garbage collector is not able to clear the Gen 0 in the first round, it will move to them to Gen 1 bucket.

Generation 2: When the Garbage collector is not able to clear the Gen 1 object, again it will move to them to Gen 2 bucket.

Generation are created to improve the performance of Garbage collector. Garbage collector spend more time on Gen 0 rather than Gen 1 and 2.

Code execution on .net F/w

codeexec

.Net Framework History

• In 2002 ( .NET Framework 1.0) Visual Studio.net
• In 2003 (.NET Framework 1.1) Visual Studio 2003
• In 2005 (.NET Framework 2.0) Visual Studio 2005
• In 2006 (.NET Framework 3.0) Visual Studio 2005
• In 2007 (.NET Framework 3.5) Visual Studio 2008
• In 2010 (.NET Framework 4.0) Visual Studio 2010
• In 2012 (.NET Framework 4.5) Visual Studio 2012
• In 2013 (.NET Framework 4.5.1) Visual Studio 2013
• In 2015 (.NET Framework 4.6) Visual Studio 2015

Key features of each .net framework

.Net Framework 1.0

• DLL Library
• Support for object oriented web app dev
• Managed code (Code which run under CLR)
• Garbage collection functionality

.Net Framework 1.1

• It came with Visual Studio 2003
• Enhancement in asp.net and ado.net
• Support for mobile asp.net controls
• Security enhancement for Asp.net
• Support for ODBC and Other database
• Support for IPV6(Internet Protocol Version 6)
• .NET Compact Framework for Small device.

.Net Framework 2.0

It came with VS 2005
– Generics
– Generic collections
– Partial class
– Nullable types
– Anonymous methods
– Data tables
– Membership providers
– New controls and features for ASP.NET
– Support for 64-bit computing
– Microsoft SQL Server integration

.Net Framework 3.0

• WPF (Windows Presentation Foundation
• WCF (Windows Communication Foundation )
• WWF (Windows Workflow Foundation)
• Windows CardSpace


.Net Framework 3.5

• It came with Visual Studio 2008
• LINQ
• Dynamic Data
• Ajax Support
• Multi Targeting Framework

.Net Framework 4.0

• It came with Visual Studio 2010
• Task Parallel Library
• Dynamic Language Runtime(DLR)
• Managed Extensibility Framework(MEF)
• CLR 4.0

.Net Framework 4.5
• It came with Visual Studio 2012
• CLR 4.0 enhanced
• Built-in support to Async
• Support for Windows Store (Metro) app dev
• WPF, WCF, WWF enhanced
• ASP.NET support enhanced
• Native support for Zip compression

.NET Framework 4.5.1
• Came with Visual Studio 2013
• Support for automatic binding redirection
• Improvements towards performance, debugging
• Expanded support for Windows Store app dev

.NET Framework 4.6
• Came with Visual Studio 2015
• A new JIT compiler named RyuJIT for 64-bit
• Support for code page encodings
• Open source .NET framework packages
• Event tracing improvements
• Support for TLS 1.1 and TLS 1.2

What type of application can we developed using .net framework?

• Window Form application
• Web application
• Mobile Application
• Services Component
• Game Development
• Wearable device software development

Summary

I hope that in this article you will be aware of all basic concepts of.net framework. Please let me share your suggestion.

Unable to access the IIS metabase


Hi

Today while working on one of my project, i was getting exception like given below.

Unable to access the IIS metabase.You do not have sufficient privilege to access IIS web sites on your machine

metadata_error

I found the two possible approach to fix this issue

1. Run the visual studio as “administrator Mode”

2. Permanently grant the IIS Metabase folder permissions to the current user.

First approach is straight forward, while for the second approach we have to go the given path

%systemroot%\System32\inetsrv\config

For this we have to do Win + E then Paste the given path in top address bar.

You will get the window like this

access

You click on “Continue” button. Now reload the project from Visual you will not get the above exception.