How to test optional dependencies

I am building a library which currently has a hard dependency on Ecto. I plan to make this dependency optional in the next version.

The implementation is no problem, but I am struggling thinking about how to test it. I am leaning towards having two independent applications that are only compiled in the test environment: one with Ecto and another without Ecto. This applications would depend on my library itself (maybe with a relative path to the upper directory) and run the required tests.

Would this be a good way to go? Or should I look into another solution?

1 Like

Optional dependencies are always fetched in the project they are declared as a top-level dependency. In a nutshell, optional dependencies are not optional in the project that declares them as optional.

Since Ecto is always available in your tests you can write your tests against Ecto and you can also write the tests that do not require Ecto.