Alex Antonov
Alex Antonov

Reputation: 15216

Is there any way to use shared examples in the ExUnit?

In RSpec it is possible to create a test and refer to it from multiple places using shared_examples. It simplifies developer's life a lot.

Is there any way to use shared examples in ExUnit?

Upvotes: 4

Views: 833

Answers (1)

michalmuskala
michalmuskala

Reputation: 11288

test macros do some bookkeeping, but ultimately they simply define a function for the test. ExUnit test code is like any other Elixir code, so you can use all the things you normally use to remove duplication. You can use macros to define common tests similar to shared_examples for you or use functions to extract common code that repeats between tests.

Upvotes: 1

Related Questions