【测试分析】基于状态的测试——实战 (4)

【测试分析】基于状态的测试——实战

  可以看到 V1->V8没有覆盖,因此再增加这三条用例即可。

  a、b、c

  

  待续.....

附录

  NModel是基础状态测试中常用的一个工具,它可以在我们列出对象的状态和执行的动作之后,自动帮我们构建状态图,并且还可以生成用例。

  下面我说一下NModel使用的具体步骤:

  1、下载NModel:

    下载地址  ,NModel的官方网站上,点击 “download” 即可下载。

【测试分析】基于状态的测试——实战

  2、下载 GLEE:

    地址: 该工具辅助NModel最终画图用的。点击Download即可:

【测试分析】基于状态的测试——实战

  3、复制dll

    两个软件安装完成之后,将 ..\GLEE\bin下的dll 拷贝到 ..\NModel\bin 下:

【测试分析】基于状态的测试——实战

  4、安装 .NET 3.5

    这里去自己电脑的 C:\Windows\Microsoft.NET\Framework\v3.5 目录下:

【测试分析】基于状态的测试——实战

    我本地安装了vs2012,因此我编译没有使用这个,而是在vs工程里面直接编译。

  5、下载demo

    起初我们可能无法自己写一个C#的程序,因此需要一个demo来参考

【测试分析】基于状态的测试——实战

  

  6、编译demo

    这里我没有使用命令行,我用vs直接打开demo工程,然后使用vs进行编译,编译的结果为dll

【测试分析】基于状态的测试——实战

  附代码:

【测试分析】基于状态的测试——实战

【测试分析】基于状态的测试——实战

using System.Collections.Generic; using NModel; using NModel.Attributes; using NModel.Execution; //using NModel.Algorithms; using System; using System.Text; namespace BookMarks { public enum OrderNum { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 } public enum OrderDesc { 初始状态, 代发货, 发货前退款, 代收货, 发货后退款, 发货后拒绝退款, 确认收货, 支付前关闭, 支付后关闭, 完成评价, 平台介入 } public static class BookMarkShow { public static OrderDesc Translation(OrderNum ordernum) { OrderDesc orderdesc = OrderDesc.初始状态; switch(ordernum) { case OrderNum.v1: orderdesc = OrderDesc.初始状态; break; case OrderNum.v2: orderdesc = OrderDesc.代发货; break; case OrderNum.v3: orderdesc = OrderDesc.发货前退款; break; case OrderNum.v4: orderdesc = OrderDesc.代收货; break; case OrderNum.v5: orderdesc = OrderDesc.发货后退款; break; case OrderNum.v6: orderdesc = OrderDesc.发货后拒绝退款; break; case OrderNum.v7: orderdesc = OrderDesc.确认收货; break; case OrderNum.v8: orderdesc = OrderDesc.支付前关闭; break; case OrderNum.v9: orderdesc = OrderDesc.支付后关闭; break; case OrderNum.v10: orderdesc = OrderDesc.完成评价; break; case OrderNum.v11: orderdesc = OrderDesc.平台介入; break; } return orderdesc; } public static void SetOrderState(OrderNum ordernum) { WebSiteModel.ordernum = ordernum; WebSiteModel.orderdesc = Translation(ordernum); } [Feature("diyibu")] public static class diyibu { [Action] // a public static void 下单后买家关闭() { BookMarkShow.SetOrderState(OrderNum.v8); } public static bool 下单后买家关闭Enabled() { return (WebSiteModel.ordernum == OrderNum.v1); } [Action] // b public static void 下单后卖家关闭() { BookMarkShow.SetOrderState(OrderNum.v8); } public static bool 下单后卖家关闭Enabled() { return (WebSiteModel.ordernum == OrderNum.v1); } [Action] // c public static void 下单后卖家超时未处理订单关闭() { BookMarkShow.SetOrderState(OrderNum.v8); } public static bool 下单后卖家超时未处理订单关闭Enabled() { return (WebSiteModel.ordernum == OrderNum.v1); } [Action] // d public static void 买家支付() { BookMarkShow.SetOrderState(OrderNum.v2); } public static bool 买家支付Enabled() { return (WebSiteModel.ordernum == OrderNum.v1); } [Action] // e public static void 卖家发货() { BookMarkShow.SetOrderState(OrderNum.v4); } public static bool 卖家发货Enabled() { return (WebSiteModel.ordernum == OrderNum.v2); } [Action] // f public static void 买家确认收货() { BookMarkShow.SetOrderState(OrderNum.v7); } public static bool 买家确认收货Enabled() { return (WebSiteModel.ordernum == OrderNum.v4); } [Action] // h public static void 买家超时未处理收货() { BookMarkShow.SetOrderState(OrderNum.v7); } public static bool 买家超时未处理收货Enabled() { return (WebSiteModel.ordernum == OrderNum.v4); } [Action] // g public static void 买家完成评价() { BookMarkShow.SetOrderState(OrderNum.v10); } public static bool 买家完成评价Enabled() { return (WebSiteModel.ordernum == OrderNum.v7); } [Action] // i public static void 发货前买家发起退款() { BookMarkShow.SetOrderState(OrderNum.v3); } public static bool 发货前买家发起退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v2); } [Action] // j public static void 发货前卖家关闭订单() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 发货前卖家关闭订单Enabled() { return (WebSiteModel.ordernum == OrderNum.v2); } [Action] // l public static void 买家撤销发货前退款申请() { BookMarkShow.SetOrderState(OrderNum.v2); } public static bool 买家撤销发货前退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v3); } [Action] // m public static void 卖家拒绝发货前退款() { BookMarkShow.SetOrderState(OrderNum.v4); } public static bool 卖家拒绝发货前退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v3); } [Action] // n public static void 买家编辑发货前申请退款() { BookMarkShow.SetOrderState(OrderNum.v3); } public static bool 买家编辑发货前申请退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v3); } [Action] // o public static void 卖家超时未处理发货前退款申请() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 卖家超时未处理发货前退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v3); } [Action] // p public static void 卖家同意发货前退款申请() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 卖家同意发货前退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v3); } [Action] // q public static void 发货后买家发起退款() { BookMarkShow.SetOrderState(OrderNum.v5); } public static bool 发货后买家发起退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v4); } [Action] // r public static void 买家撤销发货后退款申请() { BookMarkShow.SetOrderState(OrderNum.v4); } public static bool 买家撤销发货后退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // s public static void 买家编辑发货后退款申请() { BookMarkShow.SetOrderState(OrderNum.v5); } public static bool 买家编辑发货后退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // t public static void 卖家同意发货后退款申请() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 卖家同意发货后退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // u public static void 卖家超时未处理发货后退款申请() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 卖家超时未处理发货后退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // v public static void 仲裁结束() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 仲裁结束Enabled() { return (WebSiteModel.ordernum == OrderNum.v11); } [Action] // w public static void 卖家又同意退款申请() { BookMarkShow.SetOrderState(OrderNum.v9); } public static bool 卖家又同意退款申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v6); } [Action] // x public static void 卖家申诉() { BookMarkShow.SetOrderState(OrderNum.v11); } public static bool 卖家申诉Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // y public static void 卖家拒绝了发货后退款() { BookMarkShow.SetOrderState(OrderNum.v6); } public static bool 卖家拒绝了发货后退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v5); } [Action] // z public static void 买家申诉() { BookMarkShow.SetOrderState(OrderNum.v11); } public static bool 买家申诉Enabled() { return (WebSiteModel.ordernum == OrderNum.v6); } [Action] // aa public static void 买家修改发货后申请内容() { BookMarkShow.SetOrderState(OrderNum.v5); } public static bool 买家修改发货后申请内容Enabled() { return (WebSiteModel.ordernum == OrderNum.v6); } [Action] // ab public static void 买家超时未处理拒绝退款() { BookMarkShow.SetOrderState(OrderNum.v4); } public static bool 买家超时未处理拒绝退款Enabled() { return (WebSiteModel.ordernum == OrderNum.v6); } [Action] // ac public static void 拒绝退款后买家撤销申请() { BookMarkShow.SetOrderState(OrderNum.v4); } public static bool 拒绝退款后买家撤销申请Enabled() { return (WebSiteModel.ordernum == OrderNum.v6); } } } public class WebSiteModel { public static OrderNum ordernum = OrderNum.v1; public static OrderDesc orderdesc = OrderDesc.初始状态; public static ModelProgram CreateLoginModel() { return new LibraryModelProgram(typeof(WebSiteModel).Assembly, "BookMarks", new Set<string>("diyibu")); } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgzswx.html