Copeiro - testing library

After working with Elixir for a few months, I’ve noticed extra efforts by me and my colleagues when writing tests involving lists.
Usually those issues was related to ordering. Sometimes even producing flaky behavior.

With that in mind, I wrote a small library that provides a way to assert lists in an idiomatic way and does not make me feel “weird” about it.

Please, feel free to share your thoughts around the subject :raised_hands:

3 Likes

Just one comment. You don’ t need to require a module if you are importing it.

2 Likes

Personally I wouldn’t use in since it is an operator that behaves in a different way. I would use has and has not, but you will have to flip the arguments. Or name it something else.

1 Like

I’ve seen this, but it’s generally been a symptom of code that was relying on Postgres returning rows in insertion order in tests when not using an order_by clause.

IMO the flakiness there indicates a bug, so hiding it by making comparisons order-insensitive wouldn’t be ideal.

2 Likes

I’ve seen this, but it’s generally been a symptom of code that was relying on Postgres returning rows in insertion order in tests when not using an order_by clause.

Yes, that is exactly the point. In several tests the order does not matter and the insertion order is not the expected one for some runs.

IMO the flakiness there indicates a bug, so hiding it by making comparisons order-insensitive wouldn’t be ideal.

It’s not necessarily a bug in your code. In my experience it’s usually related to a missing “order_by” (in test) as you said.

Also, you should not use a function that checks if it’s a “subset” or ignore order if order is something important to your business rules.

2 Likes