VS2010 - 用于负载测试的数据库单元测试

发布于 2024-12-16 10:35:09 字数 1759 浏览 2 评论 0原文

我在 VS2010 Ulimate 中进行负载测试的单元测试时遇到问题。我想做的是测试添加和删除(到/从数据库)方法的性能。 AddCompany 方法返回添加的公司,我想将其放入集合(数组列表)中,然后在RemoveCompany 中使用它。问题出在这个数组列表上。它在静态时适用于单元测试(我正在使用 OrderedTest),但是当我在 LoadTests 中使用此 OrderedTest 时,会出现失败。这个数组列表应该是什么类型的字段以及它应该如何初始化?

[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...");
        }
    }
}

有人吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2024-12-23 10:35:09

他们建议的方法是将 ArrayList 存储在 TestContext 中。您可以使用以下代码执行此操作:
testContextInstance.Add("myArrayList", temp);
你可以使用它来检索它
ArrayList temp = (ArrayList)testContextInstance["myArrayList"];

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文