"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

May 13, 2011

C# Learnings Today

Revising C#. Yea I'm revising my C# basics. In this post we would discuss on
  •  Interfaces
  •  Generics
  •  LINQ
  • Threading in C# 
Value Type Vs Reference Type
  • Value Types - Stored in stack (int, float, double, decimal..)
  • Reference Type - Data Stored in Heap, Reference stored in Stack (Class, Interface, array, delegate)
Why Interfaces ?
  • Define methods but not implement them (Reference Type)
  • Cannot have Members 
  • Can Inherit Interfaces
Abstract Classes
  • Can contain regular, abstract and non abstract members
  • Cannot create instances of abstract classes
  • Abstract class can be derived from other abstract classes
When to use an Abstract Class and an Interface
  • Use an abstract class to provide default behavior
  • Abstract Class - creating a class library which will be widely distributed or reused
  • Use an interface to design a polymorphic hierarchy for value types  
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Interface Example
interface IExample
{
    //Method Defined, Not Implemented
    int TestInterfaceMethod(int a, int b);
}

class MyTest : IExample
{
    public int TestInterfaceMethod(int a, int b)
    {
        return (a + b);
    }
}

abstract class abstractClassExample
{
    //Has both abstract and non abstract methods
    public void BaseMethod()
    {
           Console.WriteLine("I am Base Class");
    }
    abstract public void AbstractBaseMethod();
}
class ChildClass : abstractClassExample
{
    //Implement abstract method
    override public void AbstractBaseMethod()
    {
        Console.WriteLine("Child Class OverWritten");
    } 
}

class Program
{
    static void Main()
    {
        MyTest M = new MyTest();
        Console.WriteLine(M.TestInterfaceMethod(5, 10));
        ChildClass CC = new ChildClass();
        CC.BaseMethod();
        CC.AbstractBaseMethod();
        Console.ReadKey();
    }
}

Output

Why Generics ?
  • Allow you to execute code for multiple data types
System.Collections.Generic just like:
List<T>
Dictionary<K, V>
Queue<T>
Stack<T>
How do C# generics compare to C++ templates?

Why LINQ ?
  • Language Integrated Query
  • Query on data collection similar to sql query to databases
Why I should use Linq?
When should we use LINQ?
LINQ: Introducing The Skip Last Operators
SQL Bits Session - LINQ for DBAs and SQL Developers
LINQ Notes

Threading in C#
C# - Use of Multithread (when) - (Stack Overflow Question - Reposting it)
  • You can use threads when you need different execution paths
  • Allowing requests to be processed simultaneously
  • Making efficient use of an otherwise blocked CPU 
What is the difference between Deep Copy and Shallow Copy
  • Reposting it from msdn question
  • For instance, a Person object, containing references to an Address object, several Phone objects, etc.
  • If you make a shallow copy of that Person object you now have two Person objects, but they share the Address objects and Phone objects. In other words, you only make a new Person object, and then link it up to the existing Address and Phone objects.
  • A deep copy, on the other hand, will make new copies of everything, so that both Person objects now have their own set of Address and Phone objects. 
When is a shallow copy desirable (instead of a deep copy)? (Stack Overflow Question - Reposting it)
  • In C++, you might use deep copying to avoid difficult memory management issues
  • In Java/.NET, deep copying is not necessary for those reasons. Since the languages are both garbage collected
Static Methods Example
Still remember c basics. They still seem to hold true. Tested below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int i=0;
        static void TestMethod()
        {
            //only one copy exists throught the program
            //last modified value used in this case
            i++;
            Console.WriteLine("Value of it is " + i);
            Console.ReadKey();
        }
        void TestforValueMethod()
        {
            //Local variable hides global variable
            int i=0;
            Console.WriteLine("Value of i is " + i);
            i++;
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //static method invoking without class creation
            TestMethod();
            TestMethod();
            TestMethod();
            Console.ReadKey();
            Program p = new Program();
            p.TestforValueMethod();
            TestMethod();
            Console.ReadKey();
           
        }
    }
}

Output is



More Reads
What is the difference between Arraylist.Copy() vs Arraylist.Clone()
ADO.NET: Building a Custom Data Provider for Use with the .NET Data Access Framework

Very Good Article Series for .NET Test Automation Series
I recommend Illustrated C# 2010 book. Awesome book.


Happy Reading!!

May 08, 2011

MSBI Testing

[You may also like - Database Testing, ETL Testing]

I have worked in SSIS, CDC, SSRS for one of the projects. Provided below are couple of interesting reads for MSBI testing

ETL Testing

Reposting from my Answer from SQA stackexchange

Sharing my learning's on ETL Testing
  • How errors are logged in case of failures in pulling data. Example - Network connectivity is lost while pulling data, does the job retry ?
  • Is it possible to configure toggle select only few tables to pull data to be pulled by ETL jobs
  • Test with real production data. Typically volume of data in BI system is Tera Bytes of Data
  • Look for Data Quality Issues - How Application handles nulls, blank data, Duplicate data
  • Slowly Changing Dimensions - How Changes to dimension tables are handled, Depending on type SCD 1, SCD 2 you can decide to test it the way it works
  • Manually when you have failure in pulling data in one of tables, How does it behave. Example - from source system one of table is dropped. SSIS package is not updated. In this scenarios how error is handled
More Reads
I am impressed with the pic posted below. Source - Niraj Blog. Thanks Niraj


Below articles are good refreshers.

Happy Reading!!

May 07, 2011

TestNG - Grouping Test Cases, Executing Test Multiple Times

Our next post is grouping test cases and executing a test case more than once. Below is sample code with comments and TestNG XML file for the code is also provided. We have covered
  • Grouping of Test Cases
  • Executing Particular Test Case more than once
  • Dependency based Tests
import org.testng.annotations.*;
public class TestNGExample
{
      @Test(threadPoolSize = 4, invocationCount = 5,  timeOut = 10000, groups = { "functional","BVT" })
      //This method will be run a total of 5 times using 4 threads
      public void TestCaseOne()
      {
            try
            {
                  System.out.println("In Test Case One - Functional + BVT");
            }
            catch(Exception e)
            {
                  System.out.println(e.toString());
            }
      }
     
      @Test(dependsOnMethods = "TestCaseOne" , groups = { "functional","BVT" }, invocationCount = 2,  timeOut = 10000)
      //This method will be run a twice
      //Depends on TestCaseOne
      public void TestCaseOneContinued()
      {
            try
            {
                  System.out.println("In Test Case One Continued Functional + BVT");
            }
            catch(Exception e)
            {
                  System.out.println(e.toString());
            }
      }

      @Test(groups = { "functional" })
      //Grouped as Functional Test Case
      public void TestCaseTwo()
      {
      try
      {
            System.out.println("In Test Case Two  - Functional Testcase");
      }
      catch(Exception e)
      {
            System.out.println(e.toString());
      }
      }
     
      @Test(groups = { "BVT" })
      //Part of BVT - Build Verification Cases
      public void TestCaseThree()
      {
      try
      {
            System.out.println("In Test Case Three - BVT Test Case");
      }
      catch(Exception e)
      {
            System.out.println(e.toString());
      }
      }
     
}

TestNG XML config is provided below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNGSuite" parallel="none" verbose="1">
<test name="BVTTestCaseExecution"> 
  <groups> 
    <run> 
      <include name="BVT"/> 
    </run> 
  </groups> 
  <classes> 
    <class name="TestNGExample"/> 
  </classes> 
</test>
<test name="Functional Test Cases Execution"> 
  <groups> 
    <run> 
      <include name="functional"/> 
    </run> 
  </groups> 
  <classes> 
    <class name="TestNGExample"/> 
  </classes> 
</test>
</suite>
Below is the output for the program. Right click on XML and run it as TestNG test


Good Read
How does TestNG invoke a test method using multiple threads?

Happy Reading!!

May 06, 2011

Test Automation Framework Using Selenium - Part IV

[Next Post in Series - Selenium Automation Tricks From Selenium Wiki]
[You may also like - Selenium Automation Best Practices]


In continuation with previous posts we are now going to look at running cross browser tests and specifying methods to run for each test run.

We need to edit the TestNG xml file as provided below. Below is edited XML file. You can find test's grouped, URL, browser sent as parameter.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
      <listeners>
   <listener class-name="SuiteReporter" />
   <listener class-name="TestReporter" />
   </listeners>
   <test name="TestinInternetExplorer">
   <parameter name="browserpath" value="*iehta"/>
   <parameter name="appurl" value="http://sqlandsiva.blogspot.com/"/>
      <classes>
      <class name="TestRun"/>
      <methods>
        <include name="firstPageTestCase" />
        <include name="secondPageVerifyUnOrderList" /> 
        <include name="secondPageVerifyLinks" /> 
        <include name="secondPageVerifyOrderList" /> 
      </methods> 
    </classes> 
   </test>
   <test name="TestinFirefox">
   <parameter name="browserpath" value="*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"/>
   <parameter name="appurl" value="http://sqlandsiva.blogspot.com/"/>
   <classes>
      <class name="TestRun"/>
      <methods> 
        <include name="firstPageTestCase" />
        <include name="secondPageVerifyUnOrderList" /> 
        <include name="secondPageVerifyLinks" /> 
        <include name="secondPageVerifyOrderList" /> 
      </methods> 
    </classes> 
   </test>
</suite>

Along with this change we also need to replace below method in TestRun.java file
Current Method
@BeforeTest
public void setUp()
{
      selenium = new DefaultSelenium("localhost",4444,"*iehta","http://sqlandsiva.blogspot.com/");
      selenium.start();
}

Changed / Replaced Method
      @Parameters( { "browserpath", "appurl" })
      @BeforeTest(alwaysRun = true)
      public void init(String browserpath, String appurl) {
            selenium = new DefaultSelenium("localhost", 4444, browserpath, appurl);
            selenium.start();
            selenium.deleteAllVisibleCookies();
            selenium.refresh();
      }

You can right click on XML and run it as TestNG test. Below would be result of TestNG test.


Improvements (Next Upcoming Posts)
  • Next focus is on re-running failed test cases
  • Grouping of Test cases (Will write a small example for it)
  • Threads and running a test several times (Planning for another small example script)
Stackoverflow site is awesome and very good source of learning

More Reads
Running TestNG tests from command line

Happy Learning!!