一种改进的轻量级.NET应用程序性能测试框架

发表于:2007-10-19 15:11

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:navy_koo    来源:navy_koo的专栏

3 使用示例

下面是后面部分示例中会用到的一段程序。

//被测试程序

private UInt16 _mediumFactor, _maxFactor;

public UInt16 MediumFactor

{

 get {return _mediumFactor;}

 set {_mediumFactor = value;}

}

public UInt16 MaxFactor

{

 get {return _maxFactor;}

 set {_maxFactor = value;}

}

 

 

public void FastMethod(Int32 NumberIterations)

{

 int j = 0;

 for (int i = 0;i < NumberIterations;++i)

 {

 j += i;

 }

}

 

 

public void MediumMethod(Int32 NumberIterations)

{

 int j = 0;

 for (int i = 0;i < NumberIterations;++i)

 {

 for (int k = 0; k < _mediumFactor; ++k)

 j += k;

 }

}

 

 

public void SlowMethod(Int32 NumberIterations)

{

 int j = 0;

for (int i = 0;i < NumberIterations;++i)

 {

 for (int k = 0; k < _maxFactor; ++k)

 j += k;

 }

}

 

 

正向测试

首先来看C/S程序的正向测试,

public DotNetPerformance.StraightTest.TestResult[] RunSTest()

{

 const int numberIterations = 50000000;

 DotNetPerformance.StraightTest.TestRunner tr = new DotNetPerformance.StraightTest.TestRunner();

 tr.RunTests();

 FastMethod(numberIterations);

 tr.PhaseEnd("Phase1");

 MediumMethod(numberIterations);

tr.PhaseEnd("Phase2");

 SlowMethod(numberIterations);

 tr.End("最后一个阶段");

 

 

 return tr.GetTestResult();

}

 

 

private void btnST_Click(object sender, System.EventArgs e)

{

DotNetPerformance.ResultOutput.Output.DisplayResults(RunSTest(),

DotNetPerformance.ResultOutput.DisplayOption.Chart,null);

}

2
3-1 正向测试结果-图形输出

        再来看B/S程序单个页面里的正向测试(这里用System.Threading.Thread.Sleep来模拟一段程序的执行),在结果输出时要传入页面对象用于注册脚本,从而显示输出测试结果。

m_Tester = new DotNetPerformance.StraightTest.TestRunner();

m_Tester.RunTests();

System.Threading.Thread.Sleep(1000);

m_Tester.PhaseEnd("第一阶段");

System.Threading.Thread.Sleep(100);

m_Tester.PhaseEnd("第二阶段");

System.Threading.Thread.Sleep(2000);

m_Tester.PhaseEnd("第三阶段");

System.Threading.Thread.Sleep(50);

m_Tester.PhaseEnd("第四阶段");

System.Threading.Thread.Sleep(50);

m_Tester.End("第五阶段");

 

 

WebDisplayOption _wdo = UIHelper.ToWebDisplayOption(this.ddlOutputMode.SelectedValue);

if(_wdo == WebDisplayOption.WebAlert)

 {

 DotNetPerformance.ResultOutput.Output.DisplayResults(m_Tester.GetTestResult(),_wdo,new object[]{this.Page});

 }

 else if(_wdo == WebDisplayOption.WebTable)

{

DotNetPerformance.ResultOutput.Output.DisplayResults(m_Tester.GetTestResult(),_wdo,new object[]{"",this.Page});

 }

 else if(_wdo == WebDisplayOption.WebXml)

 {

DotNetPerformance.ResultOutput.Output.DisplayResults(m_Tester.GetTestResult(),_wdo,new object[]{"",this.Page});

}

else

 {

 //

 }

22
3-2正向测试结果-Web提示输出

        对于B/S多个页面间的测试,需要用GlobalStraightTest。如果要显示测试进度还要传入一个URL(前面已解释)。

DotNetPerformance.StraightTest.GlobalStraightTest.WebContainerPage = this.Page;

DotNetPerformance.StraightTest.GlobalStraightTest.RunTests("http://localhost/LPTDemo/WaitPage.aspx");

System.Threading.Thread.Sleep(1000);

DotNetPerformance.StraightTest.GlobalStraightTest.PhaseEnd("第一个页面阶段1");

System.Threading.Thread.Sleep(100);

DotNetPerformance.StraightTest.GlobalStraightTest.PhaseEnd("第一个页面阶段2");

222
3-3 正向全局测试-进度条1

下面转到第二个页面,

Response.Redirect("MidWebForm.aspx");

 

DotNetPerformance.StraightTest.GlobalStraightTest.WebContainerPage = this.Page;

System.Threading.Thread.Sleep(50);

DotNetPerformance.StraightTest.GlobalStraightTest.PhaseEnd("第二个页面测试结束");

Response.Redirect("EndWebForm.aspx");

2222
3-4 正向全局测试-进度条2

第三个页面,

System.Threading.Thread.Sleep(150);

DotNetPerformance.StraightTest.GlobalStraightTest.End("第三个页面测试结束");

 

 

WebDisplayOption _wdo = UIHelper.ToWebDisplayOption(this.ddlOutputMode.SelectedValue);

if(_wdo == WebDisplayOption.WebAlert)

{

 DotNetPerformance.ResultOutput.Output.DisplayResults(

DotNetPerformance.StraightTest.GlobalStraightTest.GetTestResult(),_wdo,new object[]{this.Page});

}

else if(_wdo == WebDisplayOption.WebTable)

{

???? DotNetPerformance.ResultOutput.Output.DisplayResults(

DotNetPerformance.StraightTest.GlobalStraightTest.GetTestResult(),_wdo,new object[]{"",this.Page});

}

else if(_wdo == WebDisplayOption.WebXml)

{

DotNetPerformance.ResultOutput.Output.DisplayResults(

DotNetPerformance.StraightTest.GlobalStraightTest.GetTestResult(),_wdo,new object[]{"",this.Page});

}

else

{

 //

}

 

 

22222
3-5 正向全局测试结果-XML输出

33
3-6 正向测试结果-Web表格输出

2222222
3-7 正向测试结果-Web图形输出

 

32/3<123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号