我开始使用 Pharo 5 学习 Smalltalk。我现在正在关注 tutorial from the squeak guys正确掌握语法等。
我一开始只有两个类(一个BlankCell类和一个用于单元测试的BlanCellTestCase类)。 Blankcell 已经实现了一些消息,我在第 1.9 节的最后。
该行为得到了很好的实现,因为在 Playground 上:
| 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:
需要一个 bool 值,而不是一个 block 。
所以
self 断言:[ exit = #south ]。
应该写成
self 断言:退出=#south
对于字符串比较,更好的方法是使用以下内容:
self 断言:退出等于:#south
因为这样你会看到字符串的差异,并且只是 bool 失败。
<小时/>但是
Object>>assert:
需要一个 block ,而不是 bool 值。
但是,您可以在常规代码中使用此断言,而不是用于代码测试。
关于smalltalk - Pharo Smalltalk 测试失败,因为消息无法理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498666/