For a class, try having a corresponding set of test methods, where each one describes a responsibility of the object, with the first word implicitly the name of the class under test. For example, in Java:
class HtmlLinkRewriterTest ... {
void testAppendsAdditionalParameterToUrlsInHrefAttributes(){?}
void testDoesNotRewriteImageOrJavascriptLinks(){?}
void testThrowsExceptionIfHrefContainsSessionId(){?}
void testEncodesParameterValue(){?}
}
This can be read as:
HtmlLinkRewriter appends additional param to URLs in href attrs.
HtmlLinkRewriter does not rewrite image or JavaScript links.
HtmlLinkRewriter throws exception if href contains session ID.
HtmlLinkRewriter encodes parameter value.
Benefits
The tests emphasizes the object's responsibilities (or features) rather than public methods and inputs/output. This makes it easier for future engineers who want to know what it does without having to delve into the code.
These naming conventions can help point out smells. For example, when it's hard to construct a sentence where the first word is the class under test, it suggests the test may be in the wrong place. And classes that are hard to describe in general often need to be broken down into smaller classes with clearer responsibilities.
Additionally, tools can be used to help understand code quicker:

(This example shows a class in IntelliJ with the TestDox plugin giving an overview of the test.)
Remember to download this episode of Testing on the Toilet, print it, and flyer your office.
12 comments:
I wish I could print and put this on our toilet, but I work on a bank ;-(
On the subject of names, changing the case of abbreviations doesn't help readability much. How about HTMLLinkRewriterTest rather than HtmlLinkRewriterTest? CamelCase is just a guide.
I love self-documenting code. :)
Not really on topic, but this example reminds you that it's always good style to use words like "has" or "is" or "does" when dealing with anything remotely boolean. Though I always try to avoid negations like "not" (e.g. "DoesNotRewrite") and rather use positive names (dunno, "void test(!doesRewriteImage...)" or "testDoesUseStableImageLinks" or whatever). But of course I'm just saying this in general, not applicable to this snippet.
So where are the real blog posts on testing, data driven practices, extensiblity, deployemnt automation..? I really hope this isn't the best stuff Google has for testing advice.
The TestDox functionality of PHPUnit makes this "agile documentation through test names" accessible, as does its role model, the TestDox extension for JUnit.
I'd like to know more how a class in IntelliJ with the TestDox plugin gives an overview of the test.
Perhaps you guys can elaborate more. I am not feeling very motivated.
Linux 2.6.20 got released yesterday. One of the "noteworthy" news is fault injection.
Any of you guys ever used this for testing purposes? I think it could be a great aproach!
Something seems wrong here to me. Assertions about what a class or function should do or not do should be, well, assertions. Tests are attempts to make a class violate its contract; assertions (or postconditions, if you prefer) check that the contract is not being violated.
Naming test cases after aspects of the class contract implies a one-to-one relationship between test cases and postconditions. This is arbitrary and often wrong. Every test case should pass every assertion without triggering it, and there may be many more parts of the input space that need special testing than there are postconditions.
Exactly what a class should do with its assertions in production is an engineering decision, but they belong in the source code and should be checked for _every_ test case. Tests should be generated and named according to an understanding of the input space, not the class contract.
Weekly turned montly? Where's the next installment? Awaiting...
similar to testdox, there is also a spec plugin for nose (a python test runner) that just came out.
網頁設計,情趣用品店,情趣用品專賣網
A片,色情A片,免費A片,成人影片,色情影片,a片免費看,情色貼圖,情色文學,情色小說,色情小說
AV,AV女優
辣妹視訊,美女視訊,視訊交友網,視訊聊天室,視訊交友,視訊美女,免費視訊,免費視訊聊天,視訊交友90739,免費視訊聊天室,成人聊天室,視訊聊天,視訊交友aooyy
哈啦聊天室,辣妺視訊,A片,色情A片,視訊,080視訊聊天室,視訊美女34c,視訊情人高雄網,視訊交友高雄網,0204貼圖區,sex520免費影片,情色貼圖,視訊ukiss
希望大家都會非常非常幸福~
「朵朵小語‧優美的眷戀在這個世界上,最重要的一件事,就是好好愛自己。好好愛自己,你的眼睛才能看見天空的美麗,耳朵才能聽見山水的清音。好好愛自己,你才能體會所有美好的東西,所有的文字與音符才能像清泉一樣注入你的心靈。好好愛自己,你才有愛人的能力,也才有讓別人愛上你的魅力。而愛自己的第一步,就是切斷讓自己覺得黏膩的過去,以無沾無滯的輕快心情,大步走向前去。愛自己的第二步,則是隨時保持孩子般的好奇,願意接受未知的指引;也隨時可以拋卻不再需要的行囊,一路雲淡風輕。親愛的,你是天地之間獨一無二的旅人,在陽光與月光的交替之中瀟灑獨行.............................................................................................................有時,你覺得痛。胃痛的時候,接受它,承認這個疼痛是你的身體的一部份,與它和平共處。心痛的時候,接受它,承認這個經驗是你的生命的一部份,與它和平共處。抗拒痛的存在,只會讓它更要證明它的存在,於是你就更痛。所以,.無論你有多麼不喜歡痛的感覺,還是要接納這個痛的事實。與你的痛站在同一邊,不逃避,不閃躲,不再與你的痛爭執,如此,你的痛才會漸漸不再胡鬧,才會乖乖平息下去。.................心願-你許下了一個心願,你閉上眼睛,在冥想之中把這個心願交託宙給宇整個讓宇宙推動它全部的力.量去執行.,你看見星球與星球的引力牽繫著彼此,你聽見虛空與虛空.唱裡著和妙美的聲音,為了你的心願,整個宇宙正在相互傳遞,然後你放下了心願,不僅是放下,最好你還把你的心願忘記,唯有如此,它才能脫離你,發展它自己,
當它在宇宙的遊歷結束之後,它自然會來到你身邊,以你曾經希望的方式回應你,許下,只是讓它發生,放下,才是讓>它實現,你的心願使你懂得不能執著的奧秘...................
Post a Comment