[英]Pharo Smalltalk test failure because message not understood
我開始使用Pharo 5學習Smalltalk。我現在正在學習吱吱作響的家伙提供的教程,以期對語法有一定的了解,等等。
我剛開始時只有兩個類(用於單元測試的類BlankCell和BlanCellTestCase類)。 Blankcell已經實現了一些消息,我位於1.9節的結尾。
行為良好實施,因為在操場上:
| cell exit |
cell := BlankCell new.
exit := cell exitSideFor: #north.
exit = #south
"the last statement properly returns a true or false"
在測試用例上,有三個測試,只有一個失敗(與exitSide有關):
testCellExitSides
"Test the exit sides."
| cell exit |
cell := BlankCell new.
exit := cell exitSideFor: #north.
self assert: [ exit = #south ].
exit := cell exitSideFor: #east.
self assert: [ exit = #west ].
exit := cell exitSideFor: #south.
self assert: [ exit = #north ].
exit := cell exitSideFor: #west.
self assert: [ exit = #east ].
錯誤消息是
MessageNotUnderstood:BlockClosure>>ifFalse:
向doesNotUnderstand
消息發送了一個指向句子的參數[ exit = #south ]
有人知道這里可能會發生什么嗎?
TestCase>>assert:
需要一個布爾值,而不是一個塊。
所以
self assert: [ exit = #south ].
應該寫成
self assert: exit = #south
對於字符串比較,首選方法是使用以下命令:
self assert: exit equals: #south
因為那樣,您將看到字符串的差異,只是布爾失敗。
但
Object>>assert:
需要一個塊,而不是布爾值。
但是,您可以在常規代碼中使用此斷言,而不是用於代碼測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.