hubertlepicki

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:

  1. Write integration tests in the ui app, mocking my core layer (ugh)
  2. Write integration tests in the ui app, mocking my storage layer (ugh)
  3. Write integration tests in ui app without mocking anything and putting up with the dependencies
  4. Create fourth integration app solely for the purpose of running tests.

Any other options? What would you do?

Most Liked

axelson

axelson

Scenic Core Team

@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

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

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 :slight_smile:

axelson

axelson

Scenic Core Team

Yeah we are using an umbrella app which is part of why it is difficult to test the dependencies between the different apps. Maybe we should start looking at moving away from it.

OvermindDL1

OvermindDL1

I prefer to have each application as its own ‘library’ which I then include into an overall meta-application that does nothing but set up the links between the other applications. Something like having one application access another can be done by just passing the name as a config option, this also makes it really easy to test as you can essentially ‘mock’ the connection by just passing a different module into the config too.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement