开发者

english testcase parser

开发者 https://www.devze.com 2023-02-22 06:19 出处:网络
I need to make a winforms desktop application with a text box where in user (tester) will copy his script like:

I need to make a winforms desktop application with a text box where in user (tester) will copy his script like:

ADD NEW PRODUCT "chair-$50" //should invoke AddProduct(name,price) c# method
REMOVE PRODUCT "table" //should invoke RemoveProduct(name) c# method

I do not want to write parser of my own. Is there any simple framework for parsing english test case to execute methods?

Few I encountered are SpecFlow & Cucumber, but can I use开发者_如何转开发 them just for parsing purpose within my application without using any testing tool like NUnit etc.

What are best & easiest options? Can I use specflow for this?


If you've got just a few methods you want to expose this way, take input lines and parse them. You can do it in 2 lines for each method. (Code in Java, don't know C#)

 while(true){
      String s = keyboard.nextLine();//get the user input
      StringTokenizer st = new StringTokenizer(s);
      String firstToken = st.nextToken();
      if(firstToken.equals("add"))
           add(st.nextToken(), st.nextToken());
      else if(firstToken.equals("remove"))
           remove(st.nextToken());
 }


If it is just a line based command language as you show you can do it with a Regex based parser writenn by your own. Then you can use some naming convention between the line command, ie: ADD NEW PRODUCT -> Pascalize -> AddNewProduct() in your class behind, so it would be easy to extend the language to other operations. Using Convert.ChangeType to inject the parameter with the expected type of the function would be an idea too... and so on


If I were you, I would prefer write simple framework consisting of three parts:

1) Command and arguments parser
2) Settings block, which defines command to class method mapping
3) Executor block, it executes class methods and passes params according to settings

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号