Replies: 1 comment 7 replies
-
What do you think about the upcoming changes here? Notably, you can create your own plan generators: #3036 |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
I just want to start by saying the whole xstate project is really cool and it is already very useful, including @xstate/test where some of the big selling points, atleast for me, are that you can
The first point is particularly impressive and its a significant point of interest when I'm explaining xstate and @xstate/test to people, however I feel it is currently limited. So currently test generation is in terms of using methods like getSimplePathPlans/getShortestPathPlans (still not sure what the difference is between these) on a test model, which from my understanding generates plans to reach every state in the model. This might be suitable for some use cases but when I have tried to use this on a realistic project I run into some issues such as:
I understand the limitations of what paths should be tested might be from some optimisation to reduce redundant tests, however this usually means the edge cases or more complex behaviours need to be tested manually, e.g. by specifying the specific sequence of events for the behaviour but then the tests become "manual" and the promises of auto test generation feel less true. This also produces another issue where the tests are partially automated, so its up to a dev to then investigate and understand all the cases the generated tests are covering and create manual tests for the gaps, which is something that then needs to be managed as a project evolves and effectively means 2 sets of tests need to be reviewed with changes.
Suggestions
My suggestions regarding this, are to provide more options for how tests are generated which will allow the test generation to be useful for more use cases and allow combining different test generation strategies to vary the test behaviour. My ideas for test generation methods are:
getMinimumPlansToUseAllEvents
ie generate the minimum number of plans in order to use all events available in the model or at least some given events (with a limit on how many steps it can take in the model or how many times it can re-visit a single state etc).
This could also have additional configuration options like specifying the minimum/maximum number of times it should test specific events and that it should prefer the least visited paths where the model has complex paths that branch and loop back etc. to force it to discover and use different paths to achieve the targets, but also allow the testing time/effort to be limited if required for large projects. This would make sure every "action" an actor can take is tested in every state, but aim to minimise the number of tests that are generated.
I also think this behaviour of traversing the test model with a goal of using all the events would cover more realistic usage.
getMinimumComprehensivePlans
ie generate the minimum number of plans in order to visit every state and use every event/path in the model (with a limit on how many steps it can take in the model). Similar idea to the above but in this case the minimum number of plans are generated with the goal of using/visiting all the events and states in the model, with configuration options to define the maximum parameters in the attempt to do this.
Additonal Comments
For both of the methods above, if the plans were not able to achieve the targets of visiting all the states or using all the events in relevent states then the model should report this either via a warning or a test failure. This will mean a clear list of areas which were not covered by the automated tests is available when creating the manual tests to cover these gaps, and new warnings/failures appear as the system changes and new gaps appear.
I think if @xstate/test can get better at the test generation and utilised the "finite" aspect of state machine states and events a bit more, it will be an even more awesome standalone tool, and I look forward to the development.
Please let me know if anything doesnt make sense.
Beta Was this translation helpful? Give feedback.
All reactions