VS2010 - 用于负载测试的数据库单元测试
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们建议的方法是将 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"];