Hi, I’m a longtime JVM language developer getting started with my first real project destined for production using Elixir.
As a longtime JVM developer, I was delighted to see that Devcontainers has an implementation for Elixir…in the JVM world it’s been a very useful tool for me when writing tests that incorporate (real) external resources.
But I’m having one problem…I think I’d like the testcontainer to be defined in the ExTest test file, but have the container started in some way before the “main” Application is started and test execution occurs so that it can set test environment configs (like container connection properties) to be picked up during the “main” Application is started-where those configs will be used).
Is there some slight-of-hand way I could do this? I’ve included some code, with the block magically_executed_before_the_world_begins
standing in as the construct I’d like to have, if possible.
defmodule ProjectTest do
use ExUnit.Case
import Testcontainers.ExUnit
container(
:cassandra,
Testcontainers.CassandraContainer.new()
)
magically_executed_before_the_world_begins do
# is there some way to do this?
import Config
config :cassandra,
host: Testcontainers.Container.get_host(:cassandra),
port: Testcontainers.Container.get_host_port(:cassandra, 9042)
end
setup_all do
# setup_all seems to run before tests but after the
# Application under test has been started so it won't do the trick
:ok
end
test "greets the world" do
# here we can then use the Cassandra connection, initialized through
# `Application.start` to test our application
thanks for your feedback