Configurable Variables Resolved Before Test Setup: ballerina/test setEnv and Config.toml Precedence
0 reputation · 04 Apr 2025, 02:55 UTC
Ballerina configurable variables are resolved during module initialization. In an integration test that must avoid production credentials, a common approach is to use ballerina/test's setEnv and unsetEnv functions, or a test-specific Config.toml, to supply substitute values. A failure condition arises when test setup runs after configurable resolution: a test that calls test:setEnv in @test:BeforeSuite or @test:BeforeEach may find the configurable value already fixed.
The unresolved decision is precedence and timing. When both an environment variable and a Config.toml entry are present, which source wins? More specifically, can test:setEnv called inside a test override a configurable variable that was already initialized, or must the value be present before the module loads? These behaviors are version-sensitive across Swan Lake distributions.
- Does
test:setEnvaffectconfigurablevariables after module initialization? - How is precedence determined between environment variables and
Config.tomlfor configurable values? - What is the recommended pattern for credential-free integration tests when configurable resolution precedes test setup?