I have integration test setup written in Kotlin, that runs with junit (can’t change that) and is environment dependent.
We can’t use spring (which allows the expression language) either.
For example – I need the test to run if the region is AWS region ‘us-west-1’ and Account Y (both have to apply), or region ‘eu-west-2’.
The test should not run on any other combination of reagion + account.
I also have disabled if cases with similar logic – run unless this combination happens or this other one.
@EnabledOnEnvironment
does not accept this type of combined ifs.
I tried a custom condition where I test multiple conditions, and for enablement it’s fine (though not elegant).
However, when I need to disable a test on multiple conditions that have ‘or’ between them, it’s another story.
The main issue I encountered so far is how to let another developer annotate their test methods easily.
I want the logic of something like:
@DisableIf("[region=us-west-2 and account=123456789] or [region=eu-west-1]")
But I don’t want to introduce any form of a new syntax.
The best I made it so far is:
@DisabledEnvCondition(
envConditions = [
EnvCondition(name = "stage", values = ["stage1"]),
EnvCondition(name = "region", values = ["us-west-1"]),
]
)
But this only goes as far as all or none
.
To achieve my goal, I’ll have to add another layer which would end up being too complicated from the using developer point of view.
@DisabledEnvCondition(
envConditionsOr = [
allOf = [
EnvCondition(name = "account", values = ["123456789"]),
EnvCondition(name = "region", values = ["us-west-1"]),
],
allOf = [
EnvCondition(name = "region", values = ["eu-west-2"]),
]
]
)
And I’ll have to also have envConditionsAnd
and anyOf
and this is like creating a whole new framework, which I don’t want.
Any ideas?
The current solution we have is methods that combine all those, so we have 4 methods for the above condition:
- function that checks if account is …
- function that checks if region is
us-west-1
- function that checks if region is
us-west-2
- function that checks if 1 & 2 are true or 3 is true.
And we repeat that for every sub-setup.
I tried using some combinations of the @EnabledIf
and @DisabledIf` built-in into junit.