DCSIMG
February 2011 - Posts - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

February 2011 - Posts

Scrat–Copy Quality Center Test Plan Structure To Microsoft Test Manager

Scrat–Copy Quality Center Test Plan Structure To Microsoft Test Manager

Scrat is a unique migration tool from Quality Center to TFS 2010 that includes Requirements, Defects and Test Cases.

When performing migration using Scrat you will also migrate all the relations and of course the structure from Quality Center.

As you can see from the picture below the migration will also migrate the Test Plan structure from Quality Center to MTM and will allow you to start working immediately without any additional work.

So if you working with Quality Center and you want to move to Microsoft Test Manager quickly Try Scrat today!

image

SharePoint 2007 Files Restore Tool

SharePoint 2007 Files Restore Tool

I had a customer that need to restore some files from a deleted SharePoint site (long story….) in TFS 2010, the first option is to restore the entire TFS 2010 database include the SharePoint content database but instead of doing all this work I’ve written a small tool to help with that issue.

Just restore the WSS_Content database (the version before the deletion) to another sql instance  and use the tool to hook the database and restore the files you needed.

This tool can also help you export files from existing SharePoint 2007 Content Database.

Download Tool

image

Enjoy

A-s-shole Driven Development

A-s-shole Driven Development

Yes I know this sound interesting and yes it is! Smile

Yaniv Kessler has sent my that email and I felt that I need to share this knowledge with you!

Scott Berkun wrote a very nice article of what he think is the reason for all those acronyms and frameworks keep piling up in the software industry.

*** Driven development (ADD)Any team where the biggest jerk makes all the big decisions is *** driven development. All wisdom, logic or process goes out the window when Mr. *** is in the room, doing whatever idiotic, selfish thing he thinks is best. There may rules and processes, but Mr. A breaks them and people follow anyway.

Read the Full Article

Scrat Has Done It Again–Another Customer Has Left Quality Center to TFS 2010

Scrat Has Done It Again–Another Customer Has Left Quality Center to TFS 2010image

I’ve just came back from a big customer in Belgium who move his Quality Center data (thousands of items) to TFS 2010 using Scrat Migration Tool.

Scrat is a product developed by Sela Group to Convert existing Quality Center (QC) items to Microsoft TFS 2010 that includes:

  • Requirements
  • Defects
  • Test Cases
  • Attachments
  • Links between Items (Test Cases are linked to Requirements by coverage).
  • And More.

If you are using Quality Center and want to move to TFS 2010 this is your chance to do so without losing any data!

Try Scrat todayDownload Trial Version

WebTestPlugins - Why? and How

WebTestPlugins - Why? and How

In my last post I’ve talked about Increase Web Test Reponses Size using Web Test Plugins, now I would like to go one step back and talk about what is Web Test Plugin and Why you may want to use it.

Web performance tests plug-ins enable you to isolate and reuse code outside the main declarative statements in your Web performance test.

A customized Web performance test plug-in offers you a way to call some code as the Web performance test is run.

The Web performance test plug-in is run one time for every test iteration.

In addition, if you override the PreRequest or PostRequest methods in the test plug-in, those request plug-ins will run before or after each request, respectively.

You can create a customized Web performance test plug-in by deriving your own class from the WebTestPlugin base class.

Download Demo Project

Create Web Test Plugin

1. Create new image project, add reference to Microsoft.VisualStudio.QualityTools.WebTestFramework.dll located under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies.

2. Add new image and give the the desire name for the plugin, define your new class to derive from WebTestPlugin.

Now you can override the desire method and add your own code.

public class WebPluginDemo : WebTestPlugin
{
    //PrePage fires before any explicit request in the webtest. It also fires before any PreRequest method.
    public override void PrePage(object sender, PrePageEventArgs e) { base.PrePage(sender, e); }

    //PreRequest fires before ALL requests made, including redirects and dependant requests. If you want it to act on only redirects,
    //or skip redirects. use the e.Request.IsRedirectFollow property to handle code flow.
    public override void PreRequest(object sender, PreRequestEventArgs e) { base.PreRequest(sender, e); }

    //PreRequestDataBinding fires before data from the context has been bound into the request. Gives an opportunity to change the data binding.
    public override void PreRequestDataBinding(object sender, PreRequestDataBindingEventArgs e) { base.PreRequestDataBinding(sender, e); }

    //PreTransaction is fired before all user defined transaction in the test.
    public override void PreTransaction(object sender, PreTransactionEventArgs e) { base.PreTransaction(sender, e); }

    //PreWebTest fires before the first request is sent.
    public override void PreWebTest(object sender, PreWebTestEventArgs e) { base.PreWebTest(sender, e); }

    public override void PostPage(object sender, PostPageEventArgs e) { base.PostPage(sender, e); }
    public override void PostRequest(object sender, PostRequestEventArgs e) { base.PostRequest(sender, e); }
    public override void PostTransaction(object sender, PostTransactionEventArgs e) { base.PostTransaction(sender, e); }
    public override void PostWebTest(object sender, PostWebTestEventArgs e) { base.PostWebTest(sender, e); }              
}
3. Create new Test Project under the same solution and add project reference to the Class Library we created in step 1.
4. Add the Web Test Plugin into you Web Test by clicking on image, now you should see you plugin as part of the Web Test
image
Download Demo Project
Enjoy

Microsoft Visual Studio Team Explorer Everywhere 2010 with SP1

Microsoft Visual Studio Team Explorer Everywhere 2010 with SP1

sce

Just to let you know that Microsoft has release SP1 for Team Explorer Everywhere includes:

  • Auto-connect on Start-up
  • Fast Workspace Switching
  • Source Control Explorer Improvements

You can download the path from Here

More from Brian Harry

Enjoy

Increase Web Test Reponses Size

Increase Web Test Reponses Size

I just visit a customer that has a problem doing Web Test on his Web Application, the problem were that the response was cut off before web test was able to receive all the data, when he looked at the response he saw the data from the server but no all the data came back.
The response is almost 5mb and for some reason Web Test is unable to save all the data… Why?

The reason is VS has a receive buffer that defaults to 1,500,000 bytes (1.5 megabytes) and it throws away anything over that.
The number reported is what is saved in the buffer, not the number of bytes received.

In order to solve this issue you can just create a WebTestPlugin that will override  ResponseBodyCaptureLimit size limit. The code for that Plugin is super simple =

public class ResponseBodyCaptureLimitPlugin : WebTestPlugin
{
    public int ResponseSizeLimit { get; set; }
    public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
        e.WebTest.ResponseBodyCaptureLimit = this.ResponseSizeLimit;
    }
}

The only thing you need to change is before the Web Test starts is the ResponseBodyCaptureLimit value.

image

And Another tip if you want to use those Web Test scripts in Load Test you should define “Record Details” to False

Record Details – True indicates that performance counts data is collected for this HTTP request when the Web Test is added to the test mix of a load test. False indicates that data is not collected.

image

Enjoy

Integrating Code Metrics in TFS 2010 Build - WF 4.0

Integrating Code Metrics in TFS 2010 Build – WF 4.0

In my last two posts I talked about What is Code Metrics and about the Code Metrics From The Command Line - Power Tools available, in this post I’ll show how you can integrate Code Metrics as part of your Build Process without writing any custom code activity.
This is not the best solution but because Jakob Ehn – Already did an amazing work to integrate Code Metrics into Team Build 2010, I will show you how to integrate the Code Metrics into the build and find out if there were not Errors during the calculation. – Not the best solution but it’s also a nice way to get inside the Build Work Flow and learn new stuff.

So let’s get started, create new Build Definition called “Build With Metrics”, go to the Process Tab and click on the DefaultTemplate.xaml like (picture below)

Download Code Metrics Build Process Template

image

After the Build Template finish loading click on “Arguments” (Down left corner) and Create new Argument called – “CheckCodeMetrics”.

image

Now, open the Metadata property in order to define a proper display name for our new Argument.

image

You can Check-in the Build Process Template, get back to the Build Definition and hit the refresh button, and you will notice you new argument is now available under the Misc category we defined in the Metadata editor.

image 

Let’s back to our Build Process Template and let defined where to perform the Code Metrics.
There more than one please you can set the Code Metrics check, but it most be after the project or projects finished the compilation.

In this demo I’ll show how to add the Metrics Check after all Projects has complete the MsBuild build.

Navigate by the following activities:

Process-> Sequence –> Run on Agent (AgentScope) –> Type Compile, Test, and Associate Changesets and Work Items –> Sequence –> Compile, Test, and Associate Changesets and Work Items –> Try Compile and Test –> Compile and Test –> For Each Configuration in BuildSettings.PlatformConfigurations –> Compile and Test for Configuration –> If BuildSettings.HasProjectsToBuild

image

After you find the activity search for the end of it and the start of new activity called – “If Not Disable Tests”

image

Open ToolBox and search for “Control Flow” section, drag the “If” activity (Picture Above).
Click on the “IF” activity and define in the condition field - CheckCodeMetrics = True, the display name can be anything you like.

image

From the ToolBox drag new activity called Sequence (This will allow you to add more activities when the condition is true), change the activity Display Name to – “Run Code Mertics for Output Dll's and Exe's”.
Under the “Team Foundation Build Activities” section in ToolBox, drag the “InvokeProcess” activity into the new Sequence you just added ,change the the activity Display Name to – “Run Metrics.exe Power Tool”
The propose of this InvokeProcess is to run the Metrics.exe file with out build arguments.

image

Selecting the InvokeProcess activity you need to modify the properties:


As I mention above Jakob Ehn did much more advanced work, but I want to do it in the sample way of – if the Code Metrics passed by Microsoft criterion than my build is ok, In order to do so, I’ll add new argument to the Metrics.exe power tool called – successfile

/successfile -   Create .lastcodemetricsssucceeded file in output report directory if no errors occur during calculation.

FileName = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\metrics.exe")

Arguments = String.Format("/f:""{0}\*.dll"" /f:""{0}\*.exe"" /out:""{0}\CodeMetricsResult.xml"" /successfile", BinariesDirectory)

image

After the Build will run the Metrics.exe file we want to make sure the .lastcodemetricsssucceeded file exists in our BinariesDirectory.
In order to do so, drag new IF activity from the ToolBox after the InvokeProcess and add the following Condition:

Directory.GetFiles(BinariesDirectory, "*.lastcodemetricssucceeded").Length = 1

Again, you can find more technics to check if the Code Metrics Passed but this simply will tell you I the Code Metrics checked passed for all files.

Drag an additional activity to the Else road called – “SetBuildProperties”, Changed “PropertiesToSet” to “Status” and in the “Status” define what if the Code Metrics fails, I defined the build status to “Partially Succeeded”.

image

image

Drag another activity called – WriteBuildMessage, define the message you want to see if the Code Metrics check passed and make sure to change the Importance property to High.

image

Now let Check-in the Build Process File and check our new Build.

image

If the Code Metrics Calculation will failed for any reason the Build Status will be “Partially Succeeded”

Download Code Metrics Build Process Template

Enjoy.

Code Metrics From The Command Line - Power Tools

Code Metrics From The Command Line - Power Tools

In my last post I’ve talked about What is Code Metrics in Visual Studio, and how Code Metrics will allow you to monitor you code to find those un-maintainable and complex hotspots

“Microsoft just release a command line because many customers are looking for a way to generate code metrics information as part of their build process. In this way, the complexity associated with assemblies coming out of your nightly builds could potentially be tracked and examined over time, which is where I think information like this is most valuable.”

From Article from Cameron Skinner

Download Code Metrics Command Power Tool

Usage

After the installation you can find metrics.exe in - C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop

  1. metrics.exe /f:FileName /out:ResultFile.xml
  2. metrics.exe /f:*.dll /f:*.exe /out:ResultFile.xml

Example: Metrics.exe /f:metrics.exe /out:D:\MetricsResults\r.xml

The result file looks like that:

image

In the next post I’ll show how to use Metrics.exe in your build process.

Enjoy.

What is Code Metrics

What is Code Metrics

Visual Studio 2008/2010 comes with a nice tool that called – Code Metrics: “gives you the ability to dig deep to find those un-maintainable and complex hotspots” Code Metrics calculate 5 measures:

  • Lines of Code – Indicates the approximate number of lines in the code. The count is based on the IL code and is therefore not the exact number of lines in the source code file. A very high count might indicate that a type or method is trying to do too much work and should be split up. It might also indicate that the type or method might be hard to maintain.
    * Why? – Bill Gates saidMeasuring programming progress by lines of code is like measuring aircraft building progress by weight.  (Source - http://www.softwarequotes.com/printableshowquotes.aspx?id=579)
    I don’t fully agree with that say, but if Bill said so bill knows. Smile

image

  • Class Coupling - Measures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types

    image
  • Depth of Inheritance – Indicates the number of class definitions that extend to the root of the class hierarchy. The deeper the hierarchy the more difficult it might be to understand where particular methods and fields are defined or/and redefined.

    image
  • Cyclomatic Complexity –  Measures the structural complexity of the code. It is created by calculating the number of different code paths in the flow of the program. A program that has complex control flow will require more tests to achieve good code coverage and will be less maintainable.

    image
  • Maintainability Index – Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability. Color coded ratings can be used to quickly identify trouble spots in your code. A green rating is between 20 and 100 and indicates that the code has good maintainability. A yellow rating is between 10 and 19 and indicates that the code is moderately maintainable. A red rating is a rating between 0 and 9 and indicates low maintainability.
    image

How To Calculate Code Metrics in Visual Studio 2010:

1. Open Visual Studio and load the desire Solution for the Code Metrics Calculation.

2. Open Analysis Menu –> Choose “Calculate Code Metrics for Solution” and you’re Done!

image

SDP 2011 - Applied Software Testing with Visual Studio 2010

SDP 2011 - Applied Software Testing with Visual Studio 2010

Sela Developer Practice (SDP) is an annual conference held in Israel which will occur this year between 13 to 16 of March.

Sela as always will will provide an awesome event for the Tech community in Israel.

image_03D9E529

I’ll have the honor to present a lecture about Applied Software Testing with Visual Studio 2010

More posts on SDP from Sela Experts

 

   

I’ll see you there!

How To Include HTTP Headers In Web Test Recording

How To Include HTTP Headers In Web Test Recording

HTTP header fields contain the operating parameters of an HTTP request or response. With the request or response line (first line of message), they form the message header.

Here is a ScreenCast on How to Create Web Test\Coded Web Test - Screencast [HE]

While recording Web Test you will notice that Headers are not included in Web Test Requests, this because Web Test only record below header by default:

  • SOAPAction
  • Pragma
  • x-microsoftajax
  • Content-Type

image

But you can change those types by modifying registry, just add a string key with the headers that you want to record during Web Test.
How To Change Recorded Header Types:

Visual Studio 2008: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\EnterpriseTools\QualityTools\WebLoadTest

Visual Studio 2010: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\EnterpriseTools\QualityTools\WebLoadTest

Add a string value under this key with the name "RequestHeadersToRecord” and value="SOAPAction;Pragma;x-microsoftajax;Content-Type;Referrer;Accept-Encoding;Accept-Language;User-Agent"

And you can add any Http Header you like to record. (More about HTTP Headers - http://en.wikipedia.org/wiki/List_of_HTTP_headers)

Download Registry for Visual Studio 2008 | Download Registry for Visual Studio 2010

In this demo I’ve added:

  • Accept-Encoding
  • Accept-Language
  • User-Agent

And record the same requests, and the result is:

image

Why? sometimes you just want to see those values in your web test and sometimes you want to Data Bind the headers value to a DataSource.

Download Registry for Visual Studio 2008 | Download Registry for Visual Studio 2010