hauks96
Phoenix - Unit testing without repository DB connection
I am trying to run unit tests in a phoenix project. The tests I am writing mock functions that call Ecto.Adapters.SQL.Query() so I do not need a database connection for the tests to succeed.
When I run the tests with $ mix test/unit/my_test.exs I get the following error. I have no Idea how I can disable the repository connection attempt, any ideas?
16:29:41.248 [error] GenServer #PID<0.376.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
16:29:41.264 [error] GenServer #PID<0.382.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
Here is a sample that fails with this error
defmodule Test.Unit.MyTest do
import Mock
use ExUnit.Case
@moduletag :unit_test
describe "one equals two" do
test "returns true" do
assert 1 == 2
end
end
end
Marked As Solved
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
If you don’t need your application to be booted for these tests simply mix test --no-start
4
Also Liked
speeddragon
Also if you have some aliases in mix.exs file for test command like ecto.create, you need to remove them. I was trying to understand Ecto calls when running the unit tests.
1
Popular in Questions
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
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
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hi!
In PHP: $SERVER['SERVERADDR'] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Other popular topics
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New








