好的自動化測試該具備什麼屬性?

What are the Qualities of a Good Test?
http://www.infoq.com/news/2008/10/qualities_good_test

Oct 03, 2008
Posted by Mark Levison
Published in Info Queue

什麼是一個好的自動化測試? 我們如何知道我們是否寫出好的測試?

Kent Beck 寫道, 好的測試應該是:
# Isolated (unaffected by the presence, absence, or results of other tests)
# Automated
# Quick to write
# Quick to run
# Unique (providing confidence not provided by other tests/uncorrelated with other tests)

Roy Osherove 加上三個基本的屬性: maintainable, trustworthy and readable.

Mike Hill 有一個更長的列表來描述:
# It is short, typically under a dozen lines of code.
# It does not test the object inside the running app, but instead in a purpose-built testing application.
# It invokes only a tiny portion of the code, most usually a single branch of a single function.
# It is written gray-box, i.e. it reads as if it were black-box, but sometimes takes advantage of white-box knowledge. (Typically a critical factor in avoiding combinatoric issues.)
# It is coded to the same standard as shipping code, i.e. the team's best current understanding of coding excellence.
# In combination with all other microtests of an app, it serves as a 'gateway-to-commit'. That is, a developer is encouraged to commit anytime all microtests run green, and discouraged (strongly, even nastily) to commit otherwise.
# It takes complete control of the object-under-test and is therefore self-contained, i.e. running with no dependencies on anything other than the testing code and its dependency graph.
# It runs in an extremely short time.
# It is generally written before the code-change it is meant to test.
# It avoids most or all usage of 'awkward' collaborators via a variety of slip-and-fake techniques.
# ...

Mike 和 Ron Jeffries提醒我們, TDD的重要精神在於簡化設計和增加生產力. 而程式碼的品質的改進和bug的減少, 則是它所帶來的副作用.

Jeremy Miller 補充說到好的單元測試應該是:
# Order Independent and Isolated - it should be possible to run the tests in whatever order the test runner chooses.
# Intention Revealing - the best unit tests make it clear to the reader how an objects API is intended to be used.
# Easy to Setup
# Finally Ed Burnette writes: Make your unit tests repeatable in every aspect; Test your boundary conditions and Always keep your tests passing at 100%.

arrow
arrow
    全站熱搜

    kojenchieh 發表在 痞客邦 留言(0) 人氣()