QA InfoTech , Independent Software Testing Service Logo
jobs@qainfotech.com
Sales: Contact Sales +1 469-759-7848 sales@qainfotech.com
QA Infotech your Software testing partner
Menu
  • About
    • Team
    • Overview
    • Values and Culture
    • QA InfoTech Foundation
    • Careers
  • Services
    • QUALITY ENGINEERING
      • Functional Testing
      • Automation Testing
      • Mobile Testing
      • Performance Testing
      • Accessibility Testing
      • Usability Testing
      • Security Testing
      Quality ASSURANCE
      • Globalization, Translation & Localization Testing
      • Courseware & Content Testing
      • Crowdsourced Testing
      • Cloud Testing
      Software Development
      • eLearning
      • Data Sciences
      • Accessibility Development
      • Mobility Solutions
      • Web Development
      • Front End Frameworks
      • Salesforce Development
      • Cloud Solutions
      • Enterprise Content Management
      • Odoo
      • ServiceNow
      • AS400
      Digital Assurance
      • Digital Assurance
      • Data Sciences & Analytics
      • Quality Consulting & Test Center of Excellence (TCOE)
      • SAP Testing
      • Selenium Test Automation
      • Blockchain Testing
  • Verticals
    • e-learning
      List Start
    • e-Learning
    • Publishing
    • BFSI
    • Health Care
    • Media
    • Travel
    • Retail
    • Government
    • OpenERP
    • List Stop
  • Knowledge Center
    • Case Studies
    • White Paper
    • Webinars
    • Blogs
  • WebinarsNew
  • News
    • News
    • Press Release
  • Contact
  • Get A Quote
  • Home
  • »
  • Business
  • »
  • Company
  • »
  • Dot Net
  • »
  • Events
04 Dec, 2015

C#: A Review on Generics

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events
  • no comments

I think a good C# developer needs to get a handle on .NET generics.  Most of the advanced features in C# deal with lots of generics and having a very good understanding of generics will help considerably, most especially when dealing with generic delegates.  So here in this post, we will review generics.

Generic type definitions can be methods, classes, structures, and interfaces.

// an example generic class
public class MyGenericClass<T>
{
    public T MyProperty;
}

 

 

The placeholders (e.g. <T>) are called generic type parameters, or type parameters.

You specify the actual types to substitute for the type parameters during instantiation.

// instantiate generic class with string type
MyGenericClass<string> c = new MyGenericClass<string>();

 

 

When instantiated, a generic type definition becomes a constructed generic type.

You can place limits or constraints on generic type parameters.

// limit type to value types except Nullable
public class MyGenericClass<T> where T : struct {/*...*/}

// limit type to reference types which can include classes,
//  interfaces, delegates, and array types
public class MyGenericClass<T> where T : class {/*...*/}

// limit type to types with public parameterless constructor
// must be specified last in multiple constraints
public class MyGenericClass<T> where T : new() {/*...*/}

// limit type to specified base class or to types derived from it
public class MyGenericClass<T> where T : MyBaseClass {/*...*/}

// limit type to specified interface or to types that implement it
public class MyGenericClass<T> where T : IMyInterface {/*...*/}

// limit type to specified type parameter    

// in a generic member function, it limits its type to the type 
//  parameter of the containing type
public class MyGenericClass<T>
{
    void MyMethod<U>(List<U> items) where U : T {/*...*/}
}

// in a generic class, it enforces an inheritance relationship
//  between the two type parameters
public class MyGenericClass<T, U> where U : T {/*...*/}

// type parameter can have multiple constraints 
//  and constraints can also be generics
//  and constraints can be applied to multiple type parameters
public class MyGenericClass<T, U> 
    where T : MyClass, IMyInterface, System.IComparable<T>, new()
    where U : struct
{
    // ...
}

 

 

A method is considered a generic method definition if it has two parameter lists: a list of type parameters enclosed in <> and a list of formal parameters enclosed in ().  A method belonging to a generic or non-generic type does not make the method generic or non-generic.  Only the existence of the two parameter lists will make the method generic, as in the example below.

public class MyClass
{
    // a generic method inside a non-generic class
    T MyGenericMethod<T>(T arg) {/*...*/}
}

 

 

A type nested in a generic type is considered by CLR to be generic even if it doesn’t have generic type parameters of its own.  When you instantiate a nested type, you need to specify the type arguments for all enclosing generic types.

// generic type
public class MyGenericType<T, U>
{
    // nested type
    public class MyNestedType
    {
        // ...
    }
}

// ... somewhere in code you instantiate the nested type   
MyGenericType<string, int>.MyNestedType nt = 
    new MyGenericType<string, int>.MyNestedType();

 

 

The following are some common generic collection counterparts provided by the .NET framework:

  • Dictionary<TKey, TValue> which is the generic version of Hashtable.  It uses KeyValuePair<TKey, TValue> for enumeration instead of DictionaryEntry.
  • List<T> which is the generic version of ArrayList.
  • Queue<T> and Stack<T> which is the generic versions of collections with same names.
  • SortedList<TKey, TValue> which is a hybrid of a dictionary and list, just like it’s nongeneric version of same name.
  • SortedDictionary<TKey, TValue> which is a pure dictionary, and LinkedList<T>.  Both don’t have nongeneric versions.
  • Collection<T> which is a base class for generating custom collection types, ReadOnlyCollection<T> which provides read-only collection from any type implementing IList<T>, and KeyedCollection<TKey, TItem> for storing objects containing their own keys.

 

There are also generic interface counterparts for ordering and equality comparisons and for shared collection functionality:

  • System.IComparable<T> and System.IEquatable<T> which define methods for ordering comparisons and equality comparisons.
  • IComparer<T> and IEqualityComparer<T> in the System.Collections.Generic namespace, which offer alternative way for types that do not implement System.IComparable<T> and System.IEquatable<T>.  They are used by methods and constructors of many of the generic collection classes.  An example would be passing a generic IComparer<T> object to the constructor of SortedDictionary<TKey, TValue> to specify a sort order.  Generic classes Comparer<T> and EqualityComparer<T> are their base class implementations.
  • ICollection<T> which provides basic functionality for adding, removing, copying, and enumerating elements in a generic collection type.  It inherits from IEnumerable<T> and the nongeneric IEnumerable.
  • IList<T> which extends ICollection<T> with methods for indexed retrieval.
  • IDictionary<TKey, TValue> which extends ICollection<T> with methods for keyed retrieval.  Generic dictionary types also inherit from nongeneric IDictionary.
  • IEnumerable<T> which provides a generic enumerator structure used by foreach.  It inherits from nongeneric IEnumerator because MoveNext and Reset methods appear only on the nongeneric interface.  This means consumer of the nongeneric interface can also consume the generic interface because the generic interface provides for nongeneric implementation.

 

You also have generic delegates in .NET framework.  An example is the EventHandler<TEventArgs> which you can use in handling events with custom event arguments.  No need to declare your own delegate type for the event.  If you need to brush up on events and delegates, see my post on raising events and nongeneric delegates.

public event EventHandler<PublishedEventArgs> Published;

 

 

There are also a bunch of useful generic delegates available for manipulating arrays and lists

  • Action<T> which allows you to perform action on an element by passing an Action<T> delegate instance and an array to the generic method Array.ForEach<T>.  You can also pass an Action<T> delegate instance to the nongeneric method List<T>.ForEach.
  • Predicate<T> which allows you to specify a search criteria to Array’s Exists<T>, Find<T>, FindAll<T>, and so on and also to List<T>’s Exists, Find, FindAll, and so on.
  • Comparsion<T> which allows you to provide a sort order.
  • Converter<TInput, TOutput> which allows you to convert between two types of arrays or lists.

 

Ok so that’s all we have for generics.  Just a review of the basics that a C# developer need to know.

03 Dec, 2015

SQL SERVER – Two Methods to Retrieve List of Primary Keys and Foreign Keys of Database

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events
  • no comments

There are two different methods of retrieving the list of Primary Keys and Foreign Keys from database.

Method 1: INFORMATION_SCHEMA

SELECT
DISTINCT
Constraint_Name AS [Constraint],
Table_Schema AS [Schema],
Table_Name AS [TableName]
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
GO

Method 2: sys.objects

SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')
GO

I am often asked about my preferred method of retrieving list of Primary Keys and Foreign Keys from database. I have a standard answer. I prefer method 3, which is querying sys database. The reason is very simple. sys. schema always provides more information and all the data can be retrieved in our preferred fashion with the preferred filter.

Let us look at the example we have on our hand. When Information Schema is used, we will not be able to discern between primary key and foreign key; we will have both the keys together. In the case of sys schema, we can query the data in our preferred way and can join this table to another table, which can retrieve additional data from the same.

Let us play a small puzzle here. Try to modify both the scripts in such a way that we are able to see the original definition of the key, that is, create a statement for this primary key and foreign key.

If I get an appropriate answer from my readers, I will publish the solution on this blog with due credit.

02 Dec, 2015

Magic Table in SQL Server

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events
  • no comments
Magic Tables
Magic tables are nothing but the logical tables maintained by SQL server internally.
There are two types of Magic tables available in SQL server:
  • Inserted
  • Deleted
We can not see or access these tables directly, not even their data-type. The only method to have access to these tables is Triggers operation either After Trigger or Instead of trigger.
Inserting into Table (Inserted Table):
Whenever we do  insert anything in our base table in database, a table gets created automatically by the
SQL server, named as INSERTED. In this table current updated or inserted record will be available. we can access this table of record via triggers.
 
Updating Table (Inserted & Deleted Table):
Whenever we do any deletion operation on our base table, in spite of one, two tables are created, one is INSERTED and another is called DELETED. Deleted table consist of the current record after the deletion operation and  Inserted table consists of the previous record. We can access it via Triggers functionality.
 
Deleting (Deleted Table):
Whenever we do deletion in base table in database, a table gets created automatically by the SQL server, named as
DELETED table. This table consist of current updated record after deletion operation. Again we can have access to these records via triggers.
02 Dec, 2015

Hashtable in C#

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events
  • no comments

Hashtable. This optimizes lookups. It computes a hash of each key you add. It then uses this hash code to look up the element very quickly.
Don’t use this. It is an older .NET Framework type. It is slower than the generic Dictionary type. But if an old program uses Hashtable, it is helpful to know how to use this type.Dictionary
First example. We create a Hashtable with a constructor. When it is created, the Hashtable has no values. We directly assign values with the indexer, which uses the square brackets.

Next:The example adds three integer keys, with one string value each, to the Hashtable object.

Result:The program displays all the DictionaryEntry objects returned from the enumerator in the foreach-loop.

WriteLine:The WriteLine call contains a format string that displays the key-value pairs with a comma.

Based on: .NET 4.5

C# program that adds entries to Hashtable

using System;
using System.Collections;

class Program
{
    static void Main()
    {
	Hashtable hashtable = new Hashtable();
	hashtable[1] = "One";
	hashtable[2] = "Two";
	hashtable[13] = "Thirteen";

	foreach (DictionaryEntry entry in hashtable)
	{
	    Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
	}
    }
}

Output

13, Thirteen
2, Two
1, One

Foreach. You can loop through the Hashtables by using the DictionaryEntry type in a foreach-loop. You can alternatively get the Keys collection and copy it into an ArrayList.Foreach
DictionaryEntry. A DictionaryEntry contains two objects: the key and the value. This is similar to a KeyValuePair from the newer generic Dictionary.DictionaryEntryKeyValuePair
ContainsKey. You will want to call ContainsKey on your Hashtable with the key contents. This method returns true if the key is found, regardless of the value.

Also:Contains works the same way. We see an example of using the indexer with the square brackets.

C# program that uses Contains method

using System;
using System.Collections;

class Program
{
    static Hashtable GetHashtable()
    {
	// Create and return new Hashtable.
	Hashtable hashtable = new Hashtable();
	hashtable.Add("Area", 1000);
	hashtable.Add("Perimeter", 55);
	hashtable.Add("Mortgage", 540);
	return hashtable;
    }

    static void Main()
    {
	Hashtable hashtable = GetHashtable();

	// See if the Hashtable contains this key.
	Console.WriteLine(hashtable.ContainsKey("Perimeter"));

	// Test the Contains method. It works the same way.
	Console.WriteLine(hashtable.Contains("Area"));

	// Get value of Area with indexer.
	int value = (int)hashtable["Area"];

	// Write the value of Area.
	Console.WriteLine(value);
    }
}

Output

True
True
1000

Objects. An indexer is a property that receives an argument inside square brackets. The Hashtable implements indexers. It returns plain objects so you must cast them.Indexer
Multiple types. The example here adds string keys and int keys. Each of the key-value pairs has different types. You can put them all in the same Hashtable.

Warning:This code might throw exceptions. Casting is a delicate operation. It is hard to get right.

Info:If the cast was applied to a different type, the statement could throw an InvalidCastException. We avoid this with “is” or “as.”

C# program that uses multiple types

using System;
using System.Collections;

class Program
{
    static Hashtable GetHashtable()
    {
	Hashtable hashtable = new Hashtable();

	hashtable.Add(300, "Carrot");
	hashtable.Add("Area", 1000);
	return hashtable;
    }

    static void Main()
    {
	Hashtable hashtable = GetHashtable();

	string value1 = (string)hashtable[300];
	Console.WriteLine(value1);

	int value2 = (int)hashtable["Area"];
	Console.WriteLine(value2);
    }
}

Output

Carrot
1000

Cast. You can use the as-operator to attempt to cast an object to a specific reference type. If the cast does not succeed, the result will be null.Null

Is:You can also use the is-operator. This operator returns true or false based on the result.

Is

As:With Hashtable, you can reduce the number of casts by using the as-operator. This is a performance warning given by FxCop.

AsFxCop

C# program that casts Hashtable values

using System;
using System.Collections;
using System.IO;

class Program
{
    static void Main()
    {
	Hashtable hashtable = new Hashtable();
	hashtable.Add(400, "Blazer");

	// This cast will succeed.
	string value = hashtable[400] as string;
	if (value != null)
	{
	    Console.WriteLine(value);
	}

	// This cast won't succeed, but won't throw.
	StreamReader reader = hashtable[400] as StreamReader;
	if (reader != null)
	{
	    Console.WriteLine("Unexpected");
	}

	// You can get the object and test it.
	object value2 = hashtable[400];
	if (value2 is string)
	{
	    Console.Write("is string: ");
	    Console.WriteLine(value2);
	}
    }
}

Output

Blazer
is string: Blazer

Keys, values. We can loop over keys and values, or store them in an ArrayList. This example shows all the keys, then all the values, and then stores the keys in an ArrayList.

Note:This Hashtable example uses the Keys property. This property returns all the keys.

Keys:The first loop in the program loops over the collection returned by the Keys instance property on the Hashtable instance.

Values:The second loop in the program shows how to enumerate only the values in the Hashtable instance.

Console.WriteLine

Copy:We create a new ArrayList with the copy constructor and pass it the Keys (or Values) property as the argument.

ArrayList

C# program that loops over Keys, Values

using System;
using System.Collections;

class Program
{
    static void Main()
    {
	Hashtable hashtable = new Hashtable();
	hashtable.Add(400, "Blaze");
	hashtable.Add(500, "Fiery");
	hashtable.Add(600, "Fire");
	hashtable.Add(800, "Immolate");

	// Display the keys.
	foreach (int key in hashtable.Keys)
	{
	    Console.WriteLine(key);
	}

	// Display the values.
	foreach (string value in hashtable.Values)
	{
	    Console.WriteLine(value);
	}

	// Put keys in an ArrayList.
	ArrayList arrayList = new ArrayList(hashtable.Keys);
	foreach (int key in arrayList)
	{
	    Console.WriteLine(key);
	}
    }
}

Output

800       (First loop)
600
500
400
Immolate  (Second loop)
Fire
Fiery
Blaze
800       (Third loop)
600
500
400

Keys and values, notes. The Keys and Values public accessors return a collection of the keys and values in the Hashtable at the time they are accessed.

However:If you need to look at all the keys and values in pairs, it is best to enumerate the Hashtable instance itself.
Count, Clear. You can count the elements in a Hashtable with the Count property. The example also shows using the Clear method to erase all the Hashtable contents.

Tip:An alternative to Clear() is to reassign your Hashtable reference to a new Hashtable().

Note:This example shows how to use the Count property. This property returns the number of elements.

First:We add data to the Hashtable. It captures the Count, which is 4. It then uses Clear on the Hashtable, which now has 0 elements.

C# program that uses Count

using System;
using System.Collections;

class Program
{
    static void Main()
    {
	// Add four elements to Hashtable.
	Hashtable hashtable = new Hashtable();
	hashtable.Add(1, "Sandy");
	hashtable.Add(2, "Bruce");
	hashtable.Add(3, "Fourth");
	hashtable.Add(10, "July");

	// Get Count of Hashtable.
	int count = hashtable.Count;
	Console.WriteLine(count);

	// Clear the Hashtable.
	hashtable.Clear();

	// Get Count of Hashtable again.
	Console.WriteLine(hashtable.Count);
    }
}

Output

4
0

Count property, notes. Count returns the number of elements in the Hashtable. This property does not perform lengthy computations or loops.

Note:MSDN states that, for Count, “retrieving the value of this property is an O(1) operation.”

Time:This property is a constant-time accessor. It returns an integer and is a simple accessor with low resource demands.
Benchmark. We test the Hashtable collection against the Dictionary. The benchmark first populates an equivalent version of each collection.

Then:It tests one key that is found and one that is not found. It repeats this 20 million times.

Hashtable used in benchmark: C#

Hashtable hashtable = new Hashtable();
for (int i = 0; i < 10000; i++)
{
    hashtable[i.ToString("00000")] = i;
}

Dictionary used in benchmark: C#

var dictionary = new Dictionary<string, int>();
for (int i = 0; i < 10000; i++)
{
    dictionary.Add(i.ToString("00000"), i);
}

Statements benchmarked: C#

hashtable.ContainsKey("09999")
hashtable.ContainsKey("30000")

dictionary.ContainsKey("09999")
dictionary.ContainsKey("30000")

Benchmark of 20 million lookups

Hashtable result:  966 ms
Dictionary result: 673 ms

Results, benchmark. Hashtable is slower than the Dictionary code. I calculate that Hashtable here is 30% slower. This means that for strongly-typed collections, the Dictionary is faster.
Constructors. The 15 overloaded constructors provide ways to specify capacities. They let you copy existing collections. You can also specify how the hash code is computed.Constructor
A summary. Hashtable is an older collection that is obsoleted by the Dictionary collection. Knowing how to use it is critical when maintaining older programs. These programs are important.

02 Dec, 2015

Unit Test Best Practices and Guidelines

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events
  • no comments

The following are Unit Test best practices and guidelines:

  1. Test one object or class per unit test class.
    Yes, you should refactor your code if you cannot test one class only.
  2. Name your test class after the class it tests.
    If you have a class named SomeClassY, then your test class should be named SomeClassY_Tests.
  3. Perform one test per test function.
    The test class can have as many functions as you need. Perform one test per function. That doesn’t mean one Assert call. Multiple assertions might be needed to perform one test.  Think of it this way. When a test fails, you should know exactly what failed and why just because of which test function failed.
  4. A unit test should run on the Build and Continuous Integration (CI) systems.
    Unit tests are there to help you succeed and prevent you from failing. If they run rarely, they rarely help. They should run every time you check in code and every time your build kicks off. You should be automatically notified if any code you wrote breaks an existing Unit Test.
  5. A unit test should never alter the system in any way.
    Don’t touch files, databases, registry, network, etc… A test that does so is a functional test not a Unit Test. If an object cannot be tested without touching the system, refactor the object to use an Interface (and if needed a wrapper) for interacting with the system so such can be faked, or mocked with a tool such as RhinoMocks or MOQ. This is important because if a Unit Test is running on the Build or CI system, you could actually introduce a change to the system that hides a bug and allows the bug to exist in a released product.
  6. Make the test function names self documenting.
    This means if you want to test passing in a bool to FunctionX you might call your test functions something like this:
    FunctionX_True_Test()
    FunctionX_False_Test()
    Think of it this way. When a test fails, you should know exactly what failed and why just because of the function name.
  7. Never assume 100% code coverage means 100% tested.
    For example, 100% coverage of a function that takes a string as a parameter might be 100% tested with one test. However, you may need to test passing in at least five string instances to avoid all types of bugs: expected string, unexpected string, null, empty, white space, and double-byte strings. Similarly a function that takes a bool parameter should be tested with both true and false passed in.
  8. Test in the simplest way possible.
    Don’t elaborate, don’t add extra code. Just make a valid test as small as possible. Warning! That doesn’t mean you can forget the best practices and guidelines above. For example, if the simplest way is to test everything in one function do NOT do it. Follow the best practices and guidelines.
  9. Get training and keep learning about Unit Testing.
    You won’t do it correctly without training and continued learning. It doesn’t matter if you do your own research and train yourself by reading online articles, blog posts, or books. Just get yourself trained and keep learning. There are many test frameworks, mocking frameworks, wrappers (such as System Wrapper), and encapsulation issues, and without training you may end up with Unit Tests that are not maintainable. You will find many opinions about best practices, some matter, some don’t, but you should know each side of the opinions and why those opinions exist whether you agree with them or not (this list included).

I hope this list helps you.

17 Oct, 2015

Code Review Checklist – To Perform Effective Code Reviews

  • Yogeshwar Singh Chauhan
  • Business,Company,Dot Net,Events,Fun at Devlabs
  • no comments

This code review checklist helps the code reviewers and software developers (during self code review) to gain expertise in the code review process, as these points are easy to remember and follow during the code review process.

Let’s first begin with the basic code review checklist and later move on to the detailed code review checklist.

Basic Code Review Checklist

Let’s discuss about the basic code review checklist, which can be very handy if you are a beginner in code reviews and/or during initial code reviews.

 

While reviewing the code, ask yourself the following basic questions:

  1. Am I able to understand the code easily?
  2. Is the code written following the coding standards/guidelines?
  3. Is the same code duplicated more than twice?
  4. Can I unit test / debug the code easily to find the root cause?
  5. Is this function or class too big? If yes, is the function or class having too many responsibilities?

If you feel that the answer is not satisfactory to any of the above questions, then you can suggest/recommend code changes.

Detailed Code Review Checklist

The following code review checklist gives an idea about the various aspects you need to consider while reviewing the code:

1. Code formatting

While going through the code, check the code formatting to improve readability and ensure that there are no blockers:

a) Use alignments (left margin), proper white space. Also ensure that code block starting point and ending point are easily identifiable.

b) Ensure that proper naming conventions (Pascal, CamelCase etc.) have been followed.

c) Code should fit in the standard 14 inch laptop screen.  There shouldn’t be a need to scroll horizontally to view the code. In a 21 inch monitor, other windows (toolbox, properties etc.) can be opened while modifying code, so always write code keeping in view a 14 inch monitor.

d) Remove the commented code as this is always a blocker, while going through the code. Commented code can be obtained from Source Control (like SVN), if required.

2. Architecture

a) The code should follow the defined architecture.

  1. Separation of Concerns followed
    • Split into multiple layers and tiers as per requirements (Presentation, Business and Data layers).
    • Split into respective files (HTML, JavaScript and CSS).
  1. Code is in sync with existing code patterns/technologies.
  2. Design patterns: Use appropriate design pattern (if it helps), after completely understanding the problem and context.

3. Coding best practices

  1. No hard coding, use constants/configuration values.
  2. Group similar values under an enumeration (enum).
  3. Comments – Do not write comments for what you are doing, instead write comments on why you are doing. Specify about any hacks, workaround and temporary fixes. Additionally, mention pending tasks in your to-do comments, which can be tracked easily.
  4. Avoid multiple if/else blocks.
  5. Use framework features, wherever possible instead of writing custom code.

4. Non Functional requirements

a) Maintainability (Supportability) – The application should require the least amount of effort to support in near future. It should be easy to identify and fix a defect.

  1. Readability: Code should be self-explanatory. Get a feel of story reading, while going through the code. Use appropriate name for variables, functions and classes. If you are taking more time to understand the code, then either code needs refactoring or at least comments have to be written to make it clear.
  2. Testability: The code should be easy to test. Refactor into a separate function (if required). Use interfaces while talking to other layers, as interfaces can be mocked easily. Try to avoid static functions, singleton classes as these are not easily testable by mocks.
  3. Debuggability: Provide support to log the flow of control, parameter data and exception details to find the root cause easily. If you are using Log4Net like component then add support for database logging also, as querying the log table is easy.
  4. Configurability: Keep the configurable values in place (XML file, database table) so that no code changes are required, if the data is changed frequently.

b) Reusability

  1. DRY (Do not Repeat Yourself) principle: The same code should not be repeated more than twice.
  2. Consider reusable services, functions and components.
  3. Consider generic functions and classes.

c) Reliability – Exception handling and cleanup (dispose) resources.

d) Extensibility – Easy to add enhancements with minimal changes to the existing code. One component should be easily replaceable by a better component.

e) Security – Authentication, authorization, input data validation against security threats such as SQL injections and Cross Site Scripting (XSS), encrypting the sensitive data (passwords, credit card information etc.)

f) Performance

  1. Use a data type that best suits the needs such as StringBuilder, generic collection classes.
  2. Lazy loading, asynchronous and parallel processing.
  3. Caching and session/application data.

g) Scalability – Consider if it supports a large user base/data? Can this be deployed into web farms?

h) Usability – Put yourself in the shoes of a end-user and ascertain, if the user interface/API is easy to understand and use. If you are not convinced with the user interface design, then start discussing your ideas with the business analyst.

5. Object-Oriented Analysis and Design (OOAD) Principles

  1. Single Responsibility Principle (SRS): Do not place more than one responsibility into a single class or function, refactor into separate classes and functions.
  2. Open Closed Principle: While adding new functionality, existing code should not be modified. New functionality should be written in new classes and functions.
  3. Liskov substitutability principle: The child class should not change the behavior (meaning) of the parent class. The child class can be used as a substitute for a base class.
  4. Interface segregation: Do not create lengthy interfaces, instead split them into smaller interfaces based on the functionality. The interface should not contain any dependencies (parameters), which are not required for the expected functionality.
  5. Dependency Injection: Do not hardcode the dependencies, instead inject them.

In most cases the principles are interrelated, following one principle automatically satisfies other principles. For e.g: if the ‘Single Responsibility Principle’ is followed, then Reusability and Testability will automatically increase.

In a few cases, one requirement may contradict with other requirement. So need to trade-off based on the importance of the weight-age, e.g. Performance vs Security. Too many checks and logging at multiple layers (UI, Middle tier, Database) would decrease the performance of an application. But few applications, especially relating to finance and banking require multiple checks, audit logging etc. So it is ok to compromise a little on performance to provide enhanced security.

Tools for Code Reviews

  1. The first step while assessing the code quality of the entire project is through a static code analysis tool. Use the tools (based on technology) such as SonarQube, NDepend, FxCop, TFS code analysis rules. There is a myth that static code analysis tools are only for managers.
  2. Use plug-ins such as Resharper, which suggests the best practices in Visual studio.
  3. To track the code review comments use the tools like Crucible, Bitbucket and TFS code review process.

Conclusion

The above code review checklist is not exhaustive, but provides a direction to the code reviewer to conduct effective code reviews and deliver good quality code. Initially, it would take some time to review the code from various aspects. After a bit of practice, code reviewers can perform effective code reviews, without much effort and time. If you would like to become an expert code reviewer, this code review checklist serves as a great starting point. Happy Code Reviewing!

Site Categories

  • Accessibility Testing (29)
  • Automation Testing (27)
  • Banking Application Testing (2)
  • Blockchain (2)
  • Blogs (378)
  • Business (44)
  • Case Studies (37)
  • Cloud Testing (5)
  • Company (16)
  • Compatibility Testing (1)
  • DevLabs Expert Group (25)
  • DevOps (2)
  • Dot Net (27)
  • E-Learning testing (3)
  • Events (6)
  • Fun at Devlabs (1)
  • Functional Testing (4)
  • Healthcare App Testing (10)
  • Innovation (5)
  • Java (3)
  • Job Openings (31)
  • Mobile Testing (20)
  • News (144)
  • News & Updates (7)
  • Open Source (9)
  • Our-Team (9)
  • Performance Testing (24)
  • Press Releases (37)
  • QA Thought Leadership (3)
  • Salesforce App Development (2)
  • Security Testing (16)
  • Software Testing (37)
  • Testimonials (24)
  • Translation & Globalization Testing (10)
  • Uncategorized (3)
  • Usability Testing (1)
  • Webinars (26)
  • White Papers (35)
  • Popular
  • Recent
  • Tags
  • Zend Framework April 16, 2013
  • Effective Regression Testing Strategy for Localized Applications Effective Regression Testing Strategy for Localized Applications March 23, 2015
  • Moving from a commercial to an open source performance testing tool August 12, 2015
  • 3 Tier Architecture in .Net Framework March 21, 2013
  • Zend at QAIT Devlabs March 26, 2013
  • Key Focus Areas while Testing a Healthcare App Key Focus Areas while Testing a Healthcare App September 18, 2020
  • Need for the Right Performance Testing Strategy for your Mobile App Need for the Right Performance Testing Strategy for your Mobile App September 12, 2020
  • Key Points to Remember Before Starting Salesforce Customization Key Points to Remember Before Starting Salesforce Customization September 8, 2020
  • Top 5 Automation Testing Tools for Mobile Applications Top 5 Automation Testing Tools for Mobile Applications September 2, 2020
  • Improve Salesforce Application Performance Leveraging Platform Cache using Lightning Web Component Improve Salesforce Application Performance Leveraging Platform Cache using Lightning Web Component August 28, 2020
  • Jobs - 13
  • Hiring - 13
  • mobile app testing - 8
  • performance testing - 7
  • accessibility-testing - 6
  • #AccessibilityTesting - 6
  • #PerformanceTesting - 6
  • automation testing - 5
  • accessibility - 4
  • #PerformanceTestingServices - 4
  • Performance Testing Services - 4
  • mobile - 3
  • testing - 3
  • functional testing - 3
  • agile cycle - 3
  • DevOps - 3
  • performance - 3
  • software testing services - 3
  • data analytics - 3
  • #SoftwareTesting - 3
  • #TestAutomation - 3
  • #AppSecurity - 3
  • #SecureBankingApps - 3
  • #TestingBankingApplications - 3
  • #SoftwareTestingStrategy - 3

Site Archives

  • September 2020 (4)
  • August 2020 (9)
  • July 2020 (15)
  • June 2020 (9)
  • May 2020 (13)
  • April 2020 (13)
  • March 2020 (23)
  • February 2020 (7)
  • January 2020 (18)
  • December 2019 (9)
  • November 2019 (10)
  • October 2019 (8)
  • September 2019 (9)
  • August 2019 (6)
  • July 2019 (4)
  • June 2019 (7)
  • May 2019 (18)
  • April 2019 (15)
  • March 2019 (5)
  • February 2019 (1)
  • January 2019 (5)
  • December 2018 (3)
  • October 2018 (4)
  • August 2018 (4)
  • July 2018 (15)
  • June 2018 (1)
  • May 2018 (3)
  • April 2018 (7)
  • March 2018 (5)
  • February 2018 (15)
  • January 2018 (3)
  • December 2017 (8)
  • November 2017 (13)
  • October 2017 (19)
  • September 2017 (13)
  • August 2017 (11)
  • July 2017 (7)
  • June 2017 (6)
  • May 2017 (5)
  • April 2017 (2)
  • March 2017 (6)
  • January 2017 (3)
  • December 2016 (7)
  • October 2016 (3)
  • September 2016 (3)
  • August 2016 (6)
  • July 2016 (4)
  • June 2016 (3)
  • May 2016 (6)
  • April 2016 (3)
  • March 2016 (7)
  • February 2016 (3)
  • January 2016 (3)
  • December 2015 (20)
  • November 2015 (2)
  • October 2015 (28)
  • September 2015 (4)
  • August 2015 (2)
  • July 2015 (14)
  • June 2015 (2)
  • May 2015 (2)
  • April 2015 (5)
  • March 2015 (18)
  • February 2015 (11)
  • January 2015 (4)
  • December 2014 (3)
  • November 2014 (4)
  • October 2014 (6)
  • September 2014 (7)
  • August 2014 (6)
  • July 2014 (7)
  • June 2014 (6)
  • May 2014 (4)
  • April 2014 (7)
  • March 2014 (7)
  • February 2014 (8)
  • January 2014 (7)
  • December 2013 (3)
  • November 2013 (6)
  • October 2013 (6)
  • September 2013 (10)
  • August 2013 (3)
  • July 2013 (4)
  • June 2013 (6)
  • May 2013 (3)
  • April 2013 (12)
  • March 2013 (6)
  • February 2013 (2)
  • January 2013 (1)
  • December 2012 (2)
  • November 2012 (3)
  • October 2012 (3)
  • September 2012 (5)
  • August 2012 (2)
  • July 2012 (6)
  • June 2012 (1)
  • May 2012 (2)
  • April 2012 (3)
  • March 2012 (8)
  • February 2012 (4)
  • January 2012 (3)
  • December 2011 (1)
  • November 2011 (4)
  • October 2011 (3)
  • September 2011 (2)
  • August 2011 (3)
  • June 2011 (4)
  • May 2011 (1)
  • April 2011 (4)
  • February 2011 (1)
  • January 2011 (1)
  • October 2010 (2)
  • August 2010 (4)
  • July 2010 (2)
  • June 2010 (3)
  • May 2010 (3)
  • April 2010 (1)
  • March 2010 (5)
  • February 2010 (1)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (2)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (2)
  • March 2009 (2)
  • February 2009 (4)
  • December 2008 (2)
  • November 2008 (1)
  • October 2008 (1)
  • September 2008 (1)
  • August 2008 (2)
  • May 2008 (1)
  • February 2008 (1)
  • September 2007 (1)
  • August 2007 (1)
  • May 2007 (2)
  • June 2006 (1)

Tag Cloud

#AccessibilityTesting #AppSecurity #AutomationTesting #MobileAppTesting #MobileTesting #PerformanceTesting #PerformanceTestingServices #SecureBankingApps #SoftwareTestAutomation #SoftwareTesting #SoftwareTestingStrategy #TestAutomation #TestingBankingApplications .NEt accessibility accessibility-testing agile cycle automation automation testing BigData cloud computing cloud testing data analytics DevOps education functional testing functional testing services globalization Hiring Jobs localization testing mobile mobile app testing Mobile Testing Offshore QA Testing performance performance testing Performance Testing Services Security testing services Selenium Test Automation software testing software testing services technology testing xAPI

Post Calendar

January 2021
MTWTFSS
« Sep  
 123
45678910
11121314151617
18192021222324
25262728293031

About QA InfoTech

Q A QA InfoTech is a C M M i CMMi Level III and I S O ISO 9001: 2015, I S O ISO 20000-1:2011, I S O ISO 27001:2013 certified company. We are one of the reputed outsourced Q A QA testing vendors with years of expertise helping clients across the globe. We have been ranked amongst the 100 Best Companies to work for in 2010 and 2011 & 50 Best Companies to work for in 2012 , Top 50 Best IT & IT-BMP organizations to work for in India in 2014, Best Companies to work for in IT & ITeS 2016 and a certified Great Place to Work in 2017-18. These are studies conducted by the Great Place to Work® Institute. View More

Get in Touch

Please use Tab key to navigate between different form fields.

This site is automatically   protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Services

  • Functional Testing
  • Automation Testing
  • Mobile Testing
  • Performance Testing
  • Accessibility Testing
  • Security Testing
  • Localization Testing
  • Cloud Testing
  • Quality Consulting

Useful Links

  • Blogs
  • Downloads
  • Case Studies
  • Webinars
  • Team
  • Pilot Testing
  • Careers
  • QA TV
  • Contact

Office Locations

Michigan, USA
Toronto, Canada
Noida, INDIA ( HQ )
Bengaluru, INDIA
Michigan, USA

  • 32985 Hamilton Court East, Suite 121, Farmington Hills, Michigan, 48334
  • +1-469-759-7848
  • info@qainfotech.com

Toronto, Canada

  • 6 Forest Laneway, North York, Ontario, M2N5X9
  • info@qainfotech.com

Noida, INDIA ( HQ )

  • A-8, Sector 68 Noida, Uttar Pradesh, 201309
  • +91-120-6101-805 / 806
  • info@qainfotech.com

Bengaluru, INDIA

  • RMZ Ecoworld, Outer Ring Road, Bellandur, Bengaluru, Karnataka, 560103
  • +91-95600-00079
  • info@qainfotech.com

Copyright ©2020 qainfotech.com. All rights reserved | Privacy Policy | Disclaimer

Scroll
QA InfoTech logo
  • About
    ▼
    • Team
    • Values and Culture
    • Overview
    • QA InfoTech Foundation
    • Careers
  • Services
    ▼
    • Software Development
      ▼
      • eLearning
      • Data Sciences
      • Accessibility Development
      • Mobility Solutions
      • Web Development
      • Front End Frameworks
      • Salesforce Development
      • Cloud Solutions
      • Enterprise Content Management
      • Odoo
      • ServiceNow
      • AS400
    • Functional Testing Services
    • Automation Testing Services & Tools
    • Mobile Testing Services
    • Performance Testing Services
    • Accessibility Testing Services
    • Usability Testing
    • Security Testing
    • Translation & Globalization Testing
    • Courseware & Content Testing
    • Crowdsourced Testing
    • Cloud Testing
    • Digital Assurance
    • Data Sciences and Analytics
    • SAP Testing
    • Selenium Test Automation
    • Blockchain Applications Testing
  • Verticals
    ▼
    • e-Learning
    • Health Care
    • Retail
    • Publishing
    • Media
    • Government
    • BFSI
    • Travel
    • OpenERP
  • Knowledge Center
    ▼
    • Case Studies
    • White Paper
    • Webinars
    • Blogs
  • WebinarsNew
  • News
    ▼
    • News
    • Press Release
  • Contact
  • Get a Quote
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Accept CookiesPrivacy policy