Hi all! Really looking Ash and what it has to offer. I have a question regarding testing. How are people testing their Ash code? I wasn’t able to find much about it.
I think the obvious answer is to make use of Ash.Api and use that in tests but wanted to see what others are doing and what might be the best way to go about it.
Generally speaking, that is the best way You can unit test individual changes/preparations/validations if you break them out into modules, but the most standard kind of tests you’ll see are “make a changeset or query, do an action, make some assertions about the result and/or the world”.
Sweet! That’s what I figured. Are there any examples repos with some basic tests? Being relatively new to elixir/Phoenix and fairly new to Ash, it would help a lot to see some sample code following this pattern.
We often find ourselves defining the code interface for our resources simply to make our tests easier to write. It’s fine because often in liveview apps you want the code interface too - but not always.
Best way is to think of the Ash API as a context and write tests as you would for a Phoenix context module, and plain unit tests for supporting modules, although I tend to just use the API level tests to drive the resource actions and the use of those modules.
And for testing Json API, graphql and other controllers in your app, use ConnCase tests.