Testing Ash framework apps

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.

1 Like

Generally speaking, that is the best way :slight_smile: 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”.

1 Like

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.

1 Like

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.

1 Like

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.

1 Like