Monday, June 20, 2016

Static Analysis Testing with NDepend

Introduction


In this article we will talk about a static analysis tool, called NDepend, that offers a wide range of features to let the user analyze a code base, that is often described as a Swiss Army Knife for .NET developers :).
For those that don't know, the definition for Static program analysis from wikipedia is "the analysis of computer software that is performed without actually executing programs (analysis performed on executing programs is known as dynamic analysis). In most cases the analysis is performed on some version of the source code, and in the other cases, some form of the object code".

Installation


In order to use NDepend in Visual Studio, you need to download NDepend installtion zip file, from here http://www.ndepend.com/download. You can use the product, with all functionalities included, free, for 14 days. After downloading the zip file, you need to start NDepend.VisualStudioExtension.Installer.exe and choose Visual Studio versions for which you want to have NDepend.

Open Visual Studio. You will notice a new menu: NDepend.



Analyze a Visual Studio Solution


After the add-in is installed, you have to open the Visual Studio solution that contains the code that you want to analyze. You can start analyzing the code either from menu  NDepend > Attach new NDepend project to current Visual Studio solution or from the circle status icon that can be found on the bottom right of the Visual Studio window.


The dialog that will be opened will be include all .NET assemblies of the Visual Studio solution. In this dialog you have the possibility to add more .NET assemblies compiled from another solutions. 


Clicking on Analyze .NET Assemblies, will generate very fast, in a few seconds, a report with the analysis of the code source. 

Analyze .NET Applications


Besides NDepend.VisualStudioExtension.Installer.exe add-in, we can analyze .NET applications with VisualNDepend.exe that you'll find it in the downloaded zip file. With this you can analyze VS solutions and projects, analyze .NET assemblies or a set of .NET assemblies.



NDepend Report


After you start analyze the code, a report in format HTML will be generated. Also, in Visual Studio, you be asked to see the Dashboard, show graphs, browse code rules.


NDepend Dashboard looks like this:


NDepend Report looks like this:



What does NDepend report tells about the code? 
  • Application Metric: What is the topology of your application?
  • Assembly Metric: What is the size of each assembly within your application in terms of #IL instructions and others metrics?
  • VisualNDepend View: What are the sizes of your assemblies, namespaces, types and methods in terms of #IL instructions?
  • Assembly Abstracness vs. Instability: What is Abstracness/Instability principle explained in the assemblies metrics section?
  • Assembly Dependencies: What are the dependencies between assemblies in your application?
  • NDepend information and warnings: How should we organize your code:?
  • CQLinq Queries and Rules: What are the default CQLinq rules which have been violated?
Below, you can see some diagrams for a testing project that is using Page Object principles in order to perform GUI testing with selenium web driver and applitools.




NDepend Features - Rules


Go to http://www.ndepend.com/features/ in order to discover all NDepend features. Below we will talk only about code rule and code query over LINQ, which, thanks to CQLink allows us to query the code in order to identify potential problems.
There are around 200 default queries and rules that you can use to analyze the code, but you can define your own rules and queries. CQLinq editor is very easy to use and it supports code completion, includes documentation, compile error description.


After the query is compiled, it will automatically be executed and the results will be shown and will be browsable.



Below you can see some rules and queries examples, taken from NDepend site.



Conclusions


NDepend is a great static analysis tool, very well documented, easy to use, giving you insights into the health of your code.

Happy testing and... make it green, becomes a dream :).

Friday, June 17, 2016

The Agile Testing Quadrants

When we think of software quality, we must take into account all its dimensions. For each dimension a different testing approach should be used. Do we know what type of testing we should perform, when to stop testing? To answer these questions, Agile Testing Quadrants will help us cover all categories of testing we need to do. The image below shows how each of the four quadrants reflects the testing we perform.


On Y axis, tests are divided into tests that support the team or critique the product. On the X axis, tests, they are divided into business-facing and technology-facing tests.

The tests that are supporting the product, from Quadrants 1 and 2, are those that support the team while the product is developed. Quadrant 1 should include test-driven development, which is the core of agile approach. Quadrant 2 also supports the development's work, but at a higher level. The tests defined here are the result of customer's examples,  that are describing details of each story. It is possible that some tests are duplicating others from the first quadrant, but these are more system behavior oriented.

The tests that are critiquing the product should not be interpreted in a negative way. As a customer, I may think differently of a programmer, I may have different expectations related to the product behavior. Business-facing examples from Quadrant 3, help the team to design the desired product. Also, it will try to emulate the way the real user will use the application. the testing is usually performed by customers. The tests from Quadrant 4 are just as critical to agile development as to any type of software testing. They are criticizing product characteristics like performance and security.

Read more about agile testing in this book: Agile Testing: A Practical Guide for Testers and Agile Teams.

Happy testing and... make it green, becomes a dream :).

Monday, June 6, 2016

Selecting your Elements with XPath and CSSSelector

How my Desktop looks like :)?


This is an useful wall-chart from Rosetta Stone and Cookbook that covers popular technologies as XPath, CSS.

Some examples of how to use this wall-chart:

1. Use this By.CssSelector("g[id^='milestone']") to identify element below:


2. Use Instance.FindElements(By.CssSelector(".cellContent > a > div"), Ex)[i] to find all elements below: 


3. Use By.CssSelector(".ember-view.timeband-scale-format>div:first-of-type>div>ul>li>a")


Happy testing and... make it green, becomes a dream :).

Popular Posts