How to test phoenix controller?

Mix 1.8.1 (compiled with Erlang/OTP 21)
Phoenix v1.3.4

I made an phoenix app (frontend) as the (View Controller) and separate another phoenix app that only has API (Model).

Any recommendation how to test a phoenix controller on rendering and redirections?

Assert the status code?

When you say separate, how separate? Are they both part of the same umbrella project or are you making these requests over HTTP?

Hello thank you for the response, I’m making requests over HTTP, Frontend(phoenix repo) then calling API(another phoenix repo)

Exhausted:

https://hexdocs.pm/phoenix/testing_controllers.html
https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#module-controller-testing
https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#html_response/2

yet?

Programming Phoenix 1.4 has a Testing MVC - Integration Tests for Views and Controllers section
https://github.com/EQuimper/programming-phoenix-1.4/tree/master/test/rumbl_web/controllers

Though of course none of that addresses testing the frontend controllers that use an http-API.

1 Like

If you’re doing it over HTTP the thing you’re going to lose vs doing it all in one application is the out of the box per test case database isolation. However if you port https://dockyard.com/blog/2017/11/15/how-to-add-concurrent-transactional-end-to-end-tests-in-a-phoenix-powered-ember-app you’ll get that too.

1 Like