Lettuce - Behaviour-driven development

前幾天看到 Lettuce 覺得挺有趣的, 昨天一玩就玩了兩個小時, 玩到半夜兩點 …

沒想到我連做夢都在寫 test case, 然後一直到醒來腦袋還一直在想 unit test … 然後就乾脆爬了起來, 一直到天亮才爬回去睡, 結果今天真是累死了 Orz

lettuce 有趣的地方是他的 feature 語法跟 steps, 我覺得真的挺有趣的, 甚至寫法文也行 XD

feature 像是下面這樣寫

Feature: Manipulate strings  
  In order to have some fun
  As a programming beginner
  I want to manipulate strings

  Scenario: Uppercased strings
    Given I have the string "lettuce leaves"
    When I put it in upper case
    Then I see the string is "LETTUCE LEAVES"```

然後 step 像是這樣

from lettuce import * @step('I have the string "(.)"') ... def have_the_string(step, string): ... world.string = string ... @step('I put it in upper case') ... def put_it_in_upper(step): ... world.string = world.string.upper() ... @step('I see the string is "(.)"') ... def seethestring_is(step, expected): ... assert world.string == expected, ... "Got %s" % world.string```


話說 lettuce 的文件中有用到 lxml, 好像挺不錯用的, 找時間來研究一下。

另外經過推友補充還有 FreshenPyccuracy 都是 BDD 的工具。


Read more posts by this author.

Subscribe to Oceanic / 海海人生

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!