ScalaCheck 1.12 Commands API: accessing command result in the nextState() function

54 views
Skip to first unread message

Asko Laitela

unread,
Feb 1, 2015, 1:27:43 PM2/1/15
to scala...@googlegroups.com

I’m trying out ScalaCheck 1.12.1 commands API and it is great. But there’s one thing giving me trouble.

For one of my commands, I need the result of the command to implement the nextState() function. It seems in ScalaCheck 1.11 there is a trait called SetCommand that provides exactly this functionality.

Can I somehow achieve this with ScalaCheck 1.12? Simply storing the result to the Command object does not work, because nextState() is sometimes (always?) called before run().


Robert Ray

unread,
Jun 3, 2015, 2:05:16 PM6/3/15
to scala...@googlegroups.com
I need to test a Command that creates a transaction (think database) and the service self-assigns a UUID for each transaction. I need to keep track of what transactions are open in my State. How do I implement nextState()?

What I came up with was to generate my own UUID when creating the Command instance, and keep a mapping of 'fake UUID' to 'real UUID' inside the Sut type. This mapping is updated as part of run(). Other Commands that act on transactions refer to the mapping inside run() to use the 'real UUID' when talking to the service. State changes only remember the 'fake UUID'. Any outstanding transactions are cleaned up when the Sut is deleted.
Reply all
Reply to author
Forward
0 new messages