Design pattern for an MSTest automation suite in Visual Studio C#

In this test automation project I will build a Visual Studio Solution for the purpose of maintaining multiple C# projects. The solution will contain all of my QA tests for all application types within a project. For example, you may have API’s, Windows services, console applications, or in the case of this example; websites. Creating individual projects reduces the clutter of loading lots of references because each of these application types have their own set of developer tools necessary for testing. I will also create a tools project for generic, non-test specific functionality; such as random name and address generating methods. To make things easier to manage, the versioning, application configuration file (App.config), and the configuration base class is going to be placed at the solution level and subsequently linked in every project. Use the “Add as Link” feature in Visual Studio to add the Configuration.cs and AssemblyInfo.cs to each project.

To add one more layer of abstraction move the TestInitialize and TestCleanup to a base class for each test project. In this example, WebsitesTestBase is the abstract class from which every TestClass can inherit.

Visual Studio solution structure for an application test automation suite.

Basic Test Automation Visual Studio Structure Design

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="JefWordpressUrl" 
        value="http://www.jeffmsmith.com/wordpress/"/>
  </appSettings>
</configuration>

Configuration.cs

using System.Configuration;
namespace Jef.Qa
{ 
  public class Configuration 
  { 
    public string JefWordpressUrl 
    {   
      get 
      { 
         return ConfigurationManager.AppSettings["JefWordpressUrl"];
      }
    }
  }
}

WebsitesTestBase.cs

using Jef.Qa;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Jef.QA
{   
  [TestClass]
  public abstract class WebsitesTestBase : Configuration
  {
    [TestInitialize]
    public void SetUp()
    {     }     
    [TestCleanup]
    public void TearDown()
    {     }
  }
} 

JefWordpress.cs

using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Jef.QA
{
 [TestClass]
 public class JefWordpress : WebsitesTestBase
 {
   [TestMethod]
   public void TestMethod0()
   {
     Assert.IsTrue(true);
   }
   [TestMethod]
   public void TestMethod1()
   {
     Assert.IsFalse(false);
   }
 }
}
  1. No comments yet.

  1. No trackbacks yet.


+ eight = 14