csadewa

csadewa

Consumer driven contract testing in Elixir

Hi all, i am currently researching consumer driven contract testing (in particular pact.io) in hope that it would make better development collaboration for frontend - backend or service to service in microservice architecture. However, even after reading through blogs and docs regarding pact.io, i am still struggling to fully understand it’s benefit. Could you share your experience?:

  1. Worked with consumer driven contract testing before? do you find it helpful?
  2. Does consumer driven contract ensure no breaking change? Does it improve no-breaking possibility much compared to using strongly typed schema (GraphQL/gRPC) combined with schema evolution?
  3. Does consumer driven contract enable better autonomy? Enable frontend to be developed separately from backend?
  4. Does there is consumer driven contract library in elixir, especially one that follow pact specification?

Most Liked Responses

stefanchrobot

stefanchrobot

I did work in a team that had multiple services in different technologies and there was a push to do consumer-driven contract testing with Pact and it got implemented for Ruby services. At that point the tooling for Elixir was not that great so we didn’t do it in the end, but I think the biggest reason was that it was always a low priority item for us - we did have an extensive set of tests for the API, so I saw little to no value (but significant effort) in adding Pact tests.

Instead of Pact I’d suggest writing unit tests (note that here the unit of the test is a behavior/endpoint, not a module/function) this way:

describe "GET /api/foobars" do
  test "requires authorization" do
    assert %{status: 401, body: body} = get(nil, "/api/foobars")
    assert %{"error" => "Unauthorized"} = body   
  end

  test "returns a list of foobars" do
    assert %{"foobars" => []} = get!(api_key, "/api/foobars")
  end
end

The idea here is to write your tests as if they were written using an external tool (you’ll need to add some helpers for making HTTP requests), but run them inside your normal test suite (mix test) to leverage all the ExUnit goodies and keep them fast.

stefanchrobot

stefanchrobot

I certainly would call them unit tests, but then we get to the point of what is the unit of a test? I think the common approach of treating a class, module or a function a unit of a test is not really useful. For me the unit of a test is a single feature/behaviour.

In my books, an integration test is one where multiple independently-deployable services are involved.

D4no0

D4no0

I don’t know if you can call these unit tests, I usually refer to these kind of tests as integration tests, as they test the system interactions as a whole, not just isolated parts.

Where Next?

Popular in Discussions Top

Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19568 166
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
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
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
sergio_101
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
dblack
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
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement