0

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?

J.R.
  • 185
  • 1
  • 2
  • 10

1 Answers1

1

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"];

Sam Woods
  • 1,820
  • 14
  • 13
  • Could you please give an example? Cause testContextInstance has no Add method. Should I initialize this ArrayList once, in class initialization? I.e. static field? – J.R. Nov 21 '11 at 13:16
  • testContextInstance is TestContext field, not ArrayList – J.R. Nov 21 '11 at 13:21