Asserts in OSMO tests

9 views
Skip to first unread message

Bruce Trask

unread,
Jan 16, 2014, 2:40:46 PM1/16/14
to osmo...@googlegroups.com
Hello,

I am trying out a few of the example tests provided with OSMO and had a couple of questions.

On the VendingExample I noticed that the @Post seems to be the place where asserts are done.

I see in the VendingExample that the asserts are assertTrue(cents >= 0); and assert(bottles >= 0)

What is the recommended way to check for exact expected values so that I can assert that cents and bottles are the exact number they should be after each test.
Should I add a ValueSet of expected values and grab from that and assert against those?  Only trouble I could foresee is if there is a random calls.  But perhaps I need to make them deterministic.

My question is also in general, what is the assert strategies in OSMO for checking state after tests and events.  I see mention of a test oracle but do not see anything about that in the documentation.

Thanks in advance.,
Bruce

Teemu Kanstrén

unread,
Jan 16, 2014, 4:11:30 PM1/16/14
to osmo...@googlegroups.com
Hi Bruce,

 The term test oracle in general refers to any checks that people might put in their tests. In OSMO tests I generally use asserts such as you have listed when doing online testing. In offline testing it depends on your test framework for which you might generate a script for.

 As for expected values, I generally track the values as variables in the model. Makes it easier to understand the model and track the values across the methods. If you have a large set of values you might use some collection to store but how you might do that would depend on your case.

 There is no generally one right or wrong strategy to check state after tests and events. I rarely check something after the test itself but usually after each step or inside the step itself. This highlights where the test might fail faster.

 If it is a single event you are interested, I would check for that right after receiving it or triggering it in the @TestStep where it is triggered.

 If it is in some way non-deterministic such as the event might come from the network after some delay, you may need to set up some checks with timeouts or such. OSMO has no direct support for that but it should not be too hard to implement such a check using some basic Java features in your model.

 For checks against general model state I would do that in a post method or similar.And if you really want to do specific checks after the test, you could look at @LastStep or @AfterTest.

Cheers,
Teemu


--
You received this message because you are subscribed to the Google Groups "osmo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osmo-mbt+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bruce Trask

unread,
Jan 16, 2014, 7:14:35 PM1/16/14
to osmo...@googlegroups.com
Great. Thank you.
Reply all
Reply to author
Forward
0 new messages