[Cuis-dev] Testing morph collisions
Juan Vuletich
juan at cuis.st
Thu Mar 13 10:10:46 PDT 2025
Hi Ezequiel,
Testing UIs is generally considered difficult and fragile.
You raise several valid questions. I don't have good answers for any of
them.
The more 'clever' code you add, the more removed from reality the test
becomes. That increases the risk of 1) the test not testing the actual
behavior of a live UI and 2) even if the test is ok, the test will
eventually break (due to excessive assumptions on the internals of the
UI framework). This critique applies to LayoutMorphTest, that was, most
likely, written by me... As I said before, I don't have good answers in
this area.
On 3/13/2025 1:54 PM, Ezequiel Birman via Cuis-dev wrote:
> After more tinkering, I can make the test pass without sending
> *privateDisplayBounds:* It seems enough to write:
>
> test02_BoundedUnopenedMorphCollides
>
> | m1 |
>
> m1 := Morph new.
>
> "Hack to avoid opening morphs in the world.`#collides:` relies on
> the morphs having a display bound, so we use
> `findFullBoundsInOwner` for its side-effects"
> "m1 setProperty: #fullBoundsInOwner toValue: m1
> findFullBoundsInOwner."
> m1 findFullBoundsInOwner.
>
> self assert: (m1 collides: m1)
>
>
> Any objections?
>
> On Mon, 23 Dec 2024 at 22:08, Ezequiel Birman <ebirman77 at gmail.com
> <mailto:ebirman77 at gmail.com>> wrote:
>
> I've just realised that the code snippet I quoted in my previous
> message is missing the final part. Here it is in full:
>
> (UISupervisor animatedUIOf: Processor activeProcess)
> ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
> ifNil: [ | updated d |
> updated := false.
> d := Delay forMilliseconds: 10.
> UISupervisor whenUIinSafeState: [ UISupervisor
> whenUIinSafeState: [updated := true ]].
> [updated] whileFalse: [
> d wait ]].
>
>
> To clarify comment/question (3) in my previous message, If I
> remove one of *whenUIinSafeState:* leaving the snippet as this:
>
> (UISupervisor animatedUIOf: Processor activeProcess)
> ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
> ifNil: [ | updated d |
> updated := false.
> d := Delay forMilliseconds: 10.
> UISupervisor whenUIinSafeState: [updated := true ].
> [updated] whileFalse: [
> d wait ]].
>
> The LayoutMorph tests still pass.
>
> On Sat, 21 Dec 2024 at 22:32, Ezequiel Birman <ebirman77 at gmail.com
> <mailto:ebirman77 at gmail.com>> wrote:
>
> Hi! I am revisiting the /Spacewar!/ exercise from The Cuis
> Smalltalk Book, and I am testing things that deal with morph
> collisions.
>
> The *LayoutMorphTest* tests in BaseImageTests insert clever
> code before the assertions, to ensure things happen orderly:
>
> (UISupervisor animatedUIOf: Processor activeProcess)
> ifNotNil: [ :ui | ui doOneCycleNowOn: ui mainCanvas ]
> ifNil: [ | updated d |
> updated := false.
> d := Delay forMilliseconds: 10.
> UISupervisor whenUIinSafeState: [ UISupervisor
> whenUIinSafeState: [ updated := true ]].
>
>
> Since I don't need (or I can't see the need) for my tests to
> display morphs on the screen, and since
> *Morph>>collides:* relies on the morphs having a display
> bound, in my tests it was enough to insert
>
> space privateDisplayBounds: space fullBoundsInOwner
>
> before the assertions, where /space/ owns the colliding morphs
> in the test; and since I don't display things on screen,
> test runs feel snappier.
>
> 1) The thing I'm doing with *privateDisplayBounds:* will it
> come back to bite me?
> 2) Is it better, for some definition of better, for morphic
> tests to display morphs on screen while they run?
> 3) I don't understand the need for the nesting in
> *UISupervisor whenUIinSafeState: [ UISupervisor
> whenUIinSafeState: [ updated := true ]]*, I removed the outer
> level and the LayoutMorph tests still pass. Maybe by chance?
> Things are hard to debug when they behave differently when
> debugging.
> 4) Can you imagine another way of writing these kinds of tests?
>
> I attached a couple of simple examples so you don't have to
> type them.
>
> --
> Eze
>
--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250313/1a1586ce/attachment.htm>
More information about the Cuis-dev
mailing list