hubertlepicki
Integration testing Phoenix/umbrella app
So here’s the thing. I have an umbrella project with following apps:
- ui - Phoenix application
- core - my core business logic / services layer
- storage - my Ecto schemas and such
I am really careful to write code in a way that upper layer only touches one layer below. For example, my ui app does not touch the storage app in any way.
I do want to, however, write integration (selenium) tests for the thing, that’d go top to bottom. As far as I can see it, I have a few options:
- Write integration tests in the
uiapp, mocking mycorelayer (ugh) - Write integration tests in the
uiapp, mocking mystoragelayer (ugh) - Write integration tests in
uiapp without mocking anything and putting up with the dependencies - Create fourth
integrationapp solely for the purpose of running tests.
Any other options? What would you do?
Most Liked
axelson
@hubertlepicki what type of setup did you end up with? Are you using Mox in your integration tests? Probably not since Mox is more for unit testing.
A better question is how are you setting up the mocks so that you can use the mocks for unit testing but not use them for integration testing.
hubertlepicki
We went with full stack testing from our UI app. So we prepare database, open browser, it clicks around and does hit the database.
We did get with using Mox to test core app.
hubertlepicki
Right, so you most likely have an umbrella app. Umbrella apps share the configuration, so you end up with precisely the above problem.
Our app is just a folder with 3 apps now, and we require the core from ui as a dep (with path: "../core") in mix.exs, and do similar with core and db apps.
This allows us to have different configuration for test env: in core we use Mox, but in ui we don’t.
In a nutshell, we treat the other apps as if they were library dependencies. So we do have some duplication in configs, i.e. config for ui configures all 3 apps, config for core configures core and db etc.
There is a nice advantage of that: you test the db app in isolation from rest of the system, the core app is not aware at all about existence of ui. Nice bounded contexts ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









