Hello!
I am looking for a way to create unit tests for custom actions. I am aware that there are already a couple of threads discussing this topic, but the information currently available is relatively limited.
I found two ways of creating unit tests:
- Using exported JSON files containing events from the tracker: This approach makes sense, but the thread that introduced this method does not explain how to export the JSON file containing the tracker events. stephens explains that “rasa export” should do this, but “rasa export” actually exports the events from the tracker store to a configured event broker (whether it is a Kafka broker or anything else like a “SQL broker”). However, there is no option to export these events into a JSON file, so how are the JSON tracker files in the Github - RasaHQ/financial-demo repo generated? I doubt anyone wrote these manually, so this unit testing approach is basically impossible.
- Using hardcoded expected results: @koaning wrote a good example of a way to unit-test with a simple separate
TestClient
class. Obviously, the expected message could be written as a fixture in pytest, but overall this is the only feasible solution at the moment.
What do you guys think about this?