How to setup a TestApp that consumes a library in tests?

I’m working on a library, but I’m not sure how to write tests for it that involve configuration; particularly where the configuration specifies an OTP app that it should work with so I can use Application.app_dir(:my_app) (for example).

Configuration example: config :my_library, otp_app: :my_app

Is there a “standard” way of setting up another test-only OTP app that would consume a library in tests? Perhaps I’m thinking about this incorrectly, but I’d like to do something analogous to Ruby where a gem sets up a dummy rails app during tests (if it were a Rails-oriented gem), and asserts the app behaves correctly.

The closest examples I can find is Gettext and the Phoenix Endpoint tests

I guess I could always all functions that accept an options keyword list that would allow me to override whatever I want just for tests; but still, I was curious if there’s a way of doing accomplishing this.

1 Like

Its not the same thing that you are testing, but the Mix.Project.in_project helper can be used to test mix.exs project configuration. I do this in Dialyxir - in this test suite I use these fixtures. I think it would also load local config.exs file, and definitely lets you pass a config keyword list to it. The function you pass would then have the actual test/asserts.

2 Likes

Thanks! That looks like that could be it. I’ll see if I can start a new project in a test/fixtures folder, and then use Mix.Project.in_project to test the config for that app fixture. Thanks Jeremy!