51Testing软件测试论坛

标题: 有没有什么方法能把 excel 里写的接口测试用例通过代码自动生成 [打印本页]

作者: 乐哈哈yoyo    时间: 2017-6-15 15:56
标题: 有没有什么方法能把 excel 里写的接口测试用例通过代码自动生成
而不是一个接口写一个test开头的方法
  1. <span class="nd">@allure.feature</span><span class="p">(</span><span class="s">'注册'</span><span class="p">)</span>
  2. <span class="nd">@pytest.mark.parametrize</span><span class="p">(</span><span class="s">'realCode, realMessage, expeCode, expeMessage, testCaseName'</span><span class="p">,</span> <span class="n">ResultParam</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
  3. <span class="k">def</span> <span class="nf">test_register</span><span class="p">(</span><span class="n">realCode</span><span class="p">,</span> <span class="n">realMessage</span><span class="p">,</span> <span class="n">expeCode</span><span class="p">,</span> <span class="n">expeMessage</span><span class="p">,</span> <span class="n">testCaseName</span><span class="p">):</span>
  4.      <span class="k">assert</span> <span class="n">realCode</span> <span class="o">==</span> <span class="n">expeCode</span>
  5.      <span class="k">assert</span> <span class="n">realMessage</span> <span class="o">==</span> <span class="n">expeMessage</span>
  6.     <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">testCaseName</span><span class="p">)</span>


  7. <span class="nd">@allure.feature</span><span class="p">(</span><span class="s">'登录'</span><span class="p">)</span>
  8. <span class="nd">@pytest.mark.parametrize</span><span class="p">(</span><span class="s">'realCode, realMessage, expeCode, expeMessage, testCaseName'</span><span class="p">,</span> <span class="n">ResultParam</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
  9. <span class="k">def</span> <span class="nf">test_login</span><span class="p">(</span><span class="n">realCode</span><span class="p">,</span> <span class="n">realMessage</span><span class="p">,</span> <span class="n">expeCode</span><span class="p">,</span> <span class="n">expeMessage</span><span class="p">,</span> <span class="n">testCaseName</span><span class="p">):</span>
  10.      <span class="k">assert</span> <span class="n">realCode</span> <span class="o">==</span> <span class="n">expeCode</span>
  11.      <span class="k">assert</span> <span class="n">realMessage</span> <span class="o">==</span> <span class="n">expeMessage</span>
  12.      <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">testCaseName</span><span class="p">)</span>
复制代码



作者: 草帽路飞UU    时间: 2017-6-15 16:05
用Apache POI 获取excel。
作者: 乐哈哈yoyo    时间: 2017-6-15 16:06
草帽路飞UU 发表于 2017-6-15 16:05
用Apache POI 获取excel。

嗯,谢谢了!
作者: 岛屿soliloquy    时间: 2017-6-16 11:10
涨知识了。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2