摘要:本文将带你了解软件测试技术之基于模型生成自动化测试用例,希望本文对大家学测试技术有所帮助。
使用NModel自动生成测试用例中,介绍了如何通过给待测试的程序建模,生成测试用例的方法。
但前面文章的问题是,生成的都是手工的测试用例,如果让测试人员手工执行程序自动生成的测试用例,
自动产生的测试用例本就应该由程序自动执行,
这其实也就是NModel推荐的模式。
那么要让NModel自动执行产生的测试用例,那么它需要知道如何才能执行登录和注销这些动作,而且它还需要知道在执行登录操作时,User.Administrator这个抽象出来的用户在实际执行测试用例时,应该采用什么用户名等信息。而这些信息NModel自己是无法“猜测”出来的,需要测试人员的引导才能获得。
因此NModel提供了IStepper这个接口让测试人员提供所需的信息,下面是这个接口的完整定义: namespace NModel.Conformance { // Summary: // Must be implemented by an IUT for conformance testing public interface IStepper { // Summary: // Make a step according to the given action, the current state becomes the // target state of this transition. If the action is not enabled an exception // is thrown and the resulting state is undefined. An action on null may be // returned. // // Parameters: // action: CompoundTerm DoAction(CompoundTerm action); // // Summary: // Return to the initial state. If Reset is not enabled in the current state, // an exception is thrown and the resulting state is undefined and is thus not // guaranteed to be the initial state void Reset(); } }
这个接口的定义非常简单(但是实现起来就是另外一回事了),核心的函数是 DoAction,从名字可以看出,这个函数就是让测试人员自己实现前面模型中每一个动作。
而NModel的工作就是将这些动作按照模型定义好的序列组合多个基本的动作。这样多个基本动作的组合就模拟了现实生活中,用户使用产品时的用户场景。
在我们这个例子中,要实现的动作就是所有加上[Action]属性的函数,即Login_Start,Logout和WebSiteModel类里面的Initialize。
我们看Initialize和Login_Start动作的实现: private void Initialize()
{ TestSettings = TestLibrary.SetupTest();
} public CompoundTerm DoAction(CompoundTerm action)
{ switch (action.Name)
{ case "Initialize": Initialize(); break; case "Login_Start": string userName;
modelUserToRealUser.TryGetValue((string) ((CompoundTerm)action.Arguments[0])[0], out userName);
string userPass = string.Empty; switch ((string)((CompoundTerm)action.Arguments[1])[0])
{ case "Correct": userPass = realUserPassword[userName]; break; case "Incorrect":
userPass = wrongPassword; break;
} TestSettings.UserHelper.LogOn(userName, userPass); var status = LoginStatus.Success;
if (TestSettings.UserHelper.IsLoginFaled()) status = LoginStatus.Failure;
break; }
return null; }
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标软件测试之测试技术频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号