最后,你需要采用一个工厂模式的方式,告诉NModel分析哪一个Feature,创建测试用例
public class WebSiteModel { public static ModeState State = ModeState.Initializing;
public static ModelProgram CreateLoginModel() { return new LibraryModelProgram(typeof(WebSiteModel).Assembly, "TrainMode", new Set<string>("Login")); }
[Action] public static void Initialize() { State = ModeState.Running; }
public static bool InitializeEnabled() { return State == ModeState.Initializing; }
public static Set<User> UsersLoggedIn = Set<User>.EmptySet; } |
编译通过以后,先用NModel提供的图形化模型验证工具查看一下生成的模型是否正确。NModel自带的mpv.exe是用来验证模型的,但是 mpv.exe使用到一个图形布局程序GLEE需要单独下载,下载后,将Microsoft.GLEE.*.dll拷贝到NModel的bin文件夹里,就可以执行mpv.exe了。
使用下面的命令查看生成的模型:
"d:\Program Files\NModel\bin\mpv.exe" /r:TrainMode.dll TrainMode.WebSiteModel.CreateLoginModel
生成的模型应该如下图所示:
下图是放大后的结果:
如果查看模型以后,觉得没有问题,就可以生成测试用例了,这里先生成手工的测试用例,下一篇再介绍如何生成自动化的测试用例。
"d:\Program Files\NModel\bin\otg.exe" /r:TrainMode.dll /f:scenario.txt TrainMode.WebSiteModel.CreateLoginModel
下面是生成的测试用例:
TestSuite( Initialize(), Login_Start(User("Authenticated"), Password("Correct")), Login_Start(User("Administrator"), Password("Incorrect")), Logout(User("Authenticated")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Correct")), Login_Start(User("Authenticated"), Password("Correct")), Logout(User("Administrator")), Logout(User("Authenticated")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Incorrect")), Login_Start(User("Authenticated"), Password("Incorrect")) ), TestCase( Initialize(), Login_Start(User("Authenticated"), Password("Incorrect")), Login_Start(User("Administrator"), Password("Correct")), Logout(User("Administrator")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Incorrect")), Login_Start(User("Authenticated"), Password("Correct")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Correct")), Login_Start(User("Authenticated"), Password("Incorrect")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Correct")), Logout(User("Administrator")), Login_Start(User("Authenticated"), Password("Correct")) ), TestCase( Initialize(), Login_Start(User("Authenticated"), Password("Correct")), Logout(User("Authenticated")), Login_Start(User("Administrator"), Password("Correct")) ), TestCase( Initialize(), Login_Start(User("Administrator"), Password("Correct")), Logout(User("Administrator")), Login_Start(User("Authenticated"), Password("Incorrect")) ), TestCase( Initialize(), Login_Start(User("Authenticated"), Password("Correct")), Login_Start(User("Administrator"), Password("Correct")), Logout(User("Authenticated")), Logout(User("Administrator")) ), TestCase( Initialize(), Login_Start(User("Authenticated"), Password("Incorrect")), Login_Start(User("Administrator"), Password("Incorrect")) ), TestCase( Initialize(), Login_Start(User("Authenticated"), Password("Correct")), Logout(User("Authenticated")), Login_Start(User("Administrator"), Password("Incorrect")) ) ) |
文章来源于领测软件测试网 https://www.ltesting.net/