Rasa 2.X Form Unit Tests

Hi everyone,

I am currently migrating a basic bot from 1.10 to 2.3. Previously, python unit tests had been written to check that the right messages were dispatched and that the right events were triggered. After migrating the forms following the migration guide, these tests of course need a significant update. However, I can’t figure out how to properly “simulate” the form now that it is not a tangible python class.

Here is the link to 2 of the relevant (and working) 1.X tests and setup: https://pastebin.com/91yczU9R

Previously, the following function allowed us to get a list of event and message related to the FormAction execution.

def run_form(self, tracker: Tracker, domain: Optional[Dict[Text, Any]] = None):
    loop = asyncio.get_event_loop()
    self.events = loop.run_until_complete(
            dispatcher=self.dispatcher, tracker=tracker, domain=domain or {}

Any tips on how to retrieve events and messages sent by a 2.X Form and its corresponding FormValidationAction in a unit test environment? Thank you for your time.

1 Like

@jslapp This is how I used to test forms in rasa 1.10 - for Rasa 2 you just need to slightly update this as I commented out in the code (it is not a complete code but I hope it gives you the idea).

                "slot1": True,
                "slot2": None,
                SlotSet("slot1", None),
    def test_my_form(
        test_action = ActionMyForm() # ->  RASA2: change this to ActionMyFormSubmit()

        tracker = get_tracker(default_sender_id, slots_dict=slots)

        events = test_action.submit(
            default_dispatcher_collecting, tracker, default_domain_dict
        ) ## RASA2: change .submit to .run
        assert events == expected_events