silverlight
发布时间:2022-05-03 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了用TestComplete进行Silverlight的单元测试,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
Silverlight支持ScriptableType 和 ScriptableMember属性,可以让类和成员被外部访问。因此可以用
TESTComplete进行调用。 AutomatedQA网站上的这篇文章介绍了具体的测试方法:
http://www.automatedqa.com/techpapers/
TESTComplete/automated-unit-tes
Ting-of-silve
@H_
616_18@
Silverlight支持ScriptableType 和 ScriptableMember属性,可以让类和成员被外部访问。因此可以用TESTComplete进行调用。
@H_
616_18@
@H_
616_18@
AutomatedQA网站上的这篇文章介绍了具体的测试方法:
@H_
616_18@
http://www.automatedqa.com/techpapers/testcomplete/automated-unit-testing-of-silverlight-applications/
@H_
616_18@
@H_
616_18@
单元测试还是在Silverlight程序中创建的,例如:
@H_
616_18@
namespace NameExtractor
{
public class UnitTestDriver
{
//an object of the tested class NameExtractor
private NameExtractor nameExtractor;
public UnitTestDriver()
{
nameExtractor = new NameExtractor();
}
private void checkEquals(String Expected,String Actual,String Msg)
{
if (Expected != Actual)
{
String exceptionMsg = String.Format("{0} : expected {1},but was: {2}",Msg,Expected,Actual);
Exception exception = new Exception(exceptionMsg);
throw exception;
}
}
}
}
@H_
616_18@
@H_
616_18@
@H_
616_18@
@H_
616_18@
@H_
616_18@
//tests
public void Test1()
{
nameExtractor.FullName = "Mr John Greench Brown,PhD";
checkEquals("Mr",nameExtractor.title,"title is not correct");
checkEquals("John",nameExtractor.FirstName,"First Name is not correct");
checkEquals("Greench",nameExtractor.Middlename,"Middle Name is not correct");
checkEquals("Brown",nameExtractor.LastName,"last name is not correct");
checkEquals("PhD",nameExtractor.Suffix,"Suffix is not correct");
}
public void Test2()
{
nameExtractor.FullName = "John Brown";
checkEquals(""," title is not correct");
checkEquals("John"," First Name is not correct");
checkEquals(""," Middle Name is not correct");
checkEquals("Brown"," last name is not correct");
checkEquals(""," Suffix is not correct");
nameExtractor.FullName = "Mr. John Brown";
checkEquals("Mr"," Suffix is not correct");
nameExtractor.FullName = "John Brown,PhD";
checkEquals("John"," First Name is not correct");
checkEquals("Brown"," last name is not correct");
checkEquals("PhD"," Suffix is not correct");
}
@H_
616_18@
@H_
616_18@
@H_
616_18@
为了让这些单元测试代码能够被TC所调用,需要做一些额外的准备:
@H_
616_18@
private void Application_Startup(object sender,StartupEventArgs E)
{
this.RootVisual = new MainPage();
HtmlPage.RegisterScriptabLeobject("unitTestDriver",new UnitTestDriver());
}
@H_
616_18@
@H_
616_18@
添加ScriptableType和ScriptaleMember属性:
@H_
616_18@
using namespace System.Windows.browser;
namespace NameExtractor
{
[ScriptableType] //Provides scriptable access to the entire class
public class UnitTestDriver
{
…
}
}
@H_
616_18@
@H_
616_18@
@H_
616_18@
@H_
616_18@
using namespace System.Windows.browser;
namespace NameExtractor
{
public class UnitTestDriver
{
…
//tests
[ScriptableMember] //Provides scriptable access to Test1
public void Test1()
{
…
}
[ScriptableMember] //Provides scriptable access to Test2
public void Test2()
{
…
}
}
}
@H_
616_18@
@H_
616_18@
@H_
616_18@
接下来就可以在TC的脚本中调用Silverlight的单元测试代码:
@H_
616_18@
// JScript
@H_
616_18@
function GetSlObject()
{
return Sys.process("IEXPLORE",2).Page("file:///C:/MyProjects/NameExtractor/Bin/Debug/TestPage.html").Form("form1").Panel("silverLightcontrolHost").object(0);
}
@H_
616_18@
@H_
616_18@
function Main()
{
@H_
616_18@
var slObject = GetSlObject();var unitTestDriver = slObject.Content.unitTestDriver;Test1(unitTestDriver);Test2(unitTestDriver);}function Test1(unitTestDriver){try{unitTestDriver.Test1();Log.message("Test1 passed.");}catch(eX){Log.Error("Test1 Failed.",ex.description);}}function Test2(unitTestDriver){try{unitTestDriver.Test2();Log.message("Test2 passed.");}catch(eX){Log.Error("Test2 Failed.",ex.description);}}
大佬总结
以上是大佬教程为你收集整理的用TestComplete进行Silverlight的单元测试全部内容,希望文章能够帮你解决用TestComplete进行Silverlight的单元测试所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。