flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
579 stars 25 forks source link

StateMachineActions: Support `func(rapid.TB)` actions #66

Closed prashantv closed 5 months ago

prashantv commented 5 months ago

This allows reuse actions from normal tests that use testing.TB.

This is helpful for tests where there may be very specific test scenarios where some logic is abstracted into a common action.

flyingmutant commented 5 months ago

I usually write StateMachine types specifically to use them in state machine tests, so the only methods they have are the methods that StateMachineActions expect. These methods can call any kind of helpers required. Can you provide an example explaining why a StateMachine type would have methods for other scenarios as well?

prashantv commented 5 months ago

The primary motivation is to reuse actions and other test helpers across rapid tests, as well as plain tests using *testing.T or *testing.B.

In my specific scenario, I wanted to test a very specific set and order of actions in a normal test, and guarantee that runs as part of every run. This was also useful to develop new actions by using a standard test with a specific set of actions.

A couple of other benefits:

For cases where a state machine is only used for rapid tests, it's not necessary, but it helps with reusing the same type in other tests.

flyingmutant commented 5 months ago

Merged, thanks!

prashantv commented 5 months ago

Thank you!