VS2010 - DB unit tests for load testing

326 Views Asked by At

I've got problems with unit tests for load tests in VS2010 Ulimate. What I'd like to do is to test performance for Add and Remove (to/from DB) methods. AddCompany method returns added company, than I'd like to put it into a collection (arraylist) and later to use it in RemoveCompany. Problem is with this arraylist. It works for unit tests when it's static (I'm using OrderedTest) but when I use this OrderedTest in LoadTests there are failures. What type of field should be this arraylist and how it should be initialized?

[TestClass()]
public class ServiceProxyTest
{
    private TestContext testContextInstance;
    private static ArrayList temp = new ArrayList();
    private ServiceProxy target;

    [ClassInitialize]
    public static void MyClassInitialize(TestContext testContext)
    {
    }

    [TestInitialize]
    public void MyTestInitialize()
    {
        this.target = new ServiceProxy();

    }

    [TestMethod]
    [TestCategory("Unit")]
    [DataSource("System.Data.SqlClient", "...", "...", DataAccessMethod.Sequential)]
    public void AddCompanyTest()
    {
        Company companyDto = new Company
            {
               ...
        };

        var company = this.target.AddCompany(companyDto);
        temp.Add(company);

        Assert.InNotNull(company);
        Assert.AreEqual(companyDto.Name, company.Name);
    }


    [TestMethod]
    [TestCategory("Unit")]
    [DataSource("System.Data.SqlClient", "...", "...", DataAccessMethod.Sequential)]
    public void RemoveCompanyTest()
    {
        try
        {
            if(temp.Count > 0)
            {
                var company = temp[temp.Count - 1] as Company;
                this.target.RemoveCompany(company);
                Assert.IsTrue(true);
            }
            else
            {
                Assert.Fail("No items to delete");
            }

        }
        catch (FaultException)
        {
            Assert.Fail("FaultException thrown - something went wrong...");
        }
    }
}

Anyone?

1

There are 1 best solutions below

2
On

The way they suggest to do it is to store the ArrayList in the TestContext. You can do so with this code: testContextInstance.Add("myArrayList", temp); And you can retrieve it using ArrayList temp = (ArrayList)testContextInstance["myArrayList"];