简体   繁体   中英

How to run real phoenix server during test?

I'm implementing kinda tricky functionality with external libraries I can't mock. They needs to implement real requests to the server. So,

how can I run a web-server during tests implementation?

PS My config/test.exs :

config :my_reelty, MyReelty.Endpoint,
  http: [port: {:system, "PORT"}],
  url:  [host: "localhost", port: 5000] # Specific port

I'm trying to curl http://localhost:5000 but getting curl: (7) Failed to connect to localhost port 5000: Connection refused

You need to add server: true to the Endpoint 's config:

config :my_reelty, MyReelty.Endpoint, server: true

The phoenix.new may have already generated similar config with server: false (it does for me in v1.2.0), so you can just change that false to true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM