Do you think ct:require/1,2 could help you so that foo and bar SUITE would require test_stuff before it gets executed? For more information http://www.erlang.org/doc/man/ct.html#require-1
Dealing with shared helpers in Common Test suites?
-
04-10-2022 - |
Question
I've got an Erlang project comprising a bunch of different applications. I'm using Common Test to do some of the testing.
apps/foo/suites/foo_SUITE.erl
apps/bar/suites/bar_SUITE.erl
I'm starting to see duplication of utility code in those suites.
Where should I put my utility code so that it can be shared between the two suites?
I've considered adding another application:
apps/test_stuff
...but I can't make the CT suites depend on this without making the application under test depend on this (or can I?). I don't want to do that, because test_stuff
is only needed when testing.
I have a similar problem with my eunit tests, both between applications (apps/foo/test
vs. apps/bar/test
), and where I'm using similar functionality between the eunit and CT tests in the same application (apps/bar/suites
vs apps/bar/test
). Can I use the same solution for this case as well? Or do I need to ask another question about that?
No correct solution
OTHER TIPS
It depends on how you are packaging your final releases. For example, I use rebar for relase management. I have Cowboy fetched along with other dependencies for testing purposes, but in my reltool.config
, I omit it, so it doesn't get packaged with the final product. I use rebar
to run Common Test, and it's able to add Cowboy to the path without having it bundled as a lib with everything else or added as a dependency to the app I'm testing.
However, if you have another process which infers your release configuration from your dependencies, you'll have to find a way to exclude your test code when you generate a release.