13
votes

I'm writing tests of some Elixir code that interacts with SSH. In my tests, I'd like to start an SSH server that I can run my code against. I'd prefer to store this code in it's own file in the test directory, and have it imported by various different tests.

I've not been able to get this to work too well though.

I've tried creating an test/ssh_server.ex file containing a SSHServer module, but when I add import SSHServer to my tests, I get:

(CompileError) test/end_to_end_test.exs:13: module SSHServer is not loaded and could not be found

Am I missing something? Is there some way to force mix test to import my test/ssh_server.ex file?

2

2 Answers

15
votes

I've currently got around this by manually loading the code from my test_helper.exs file:

Code.load_file("test/ssh_server.ex")
2
votes

Compile the module, then it will be available.

This can be done in either iex

iex > c "test/ssh_server.ex"

or with elixirc

elixirc "test/ssh_server.ex"

http://elixir-lang.org/getting-started/modules.html#compilation