Reputation: 378
I want to be able to disable a JUnit5 test based on the file seperator the OS
uses.
For example the windows file seperator is \
and a sample path would be src\resources\fou
.
On another OS
the file seperator could be /
(maybe MAC?).
I want my test to run only when the file seperator is \
.
I found this: @EnabledIfSystemProperty(named = "file.separator", matches = "[/]")
so i changed the /
to \
to match the windows file seperator, but it didn't work giving me this error:
failed to evaluate condition
.
Upvotes: 0
Views: 178
Reputation: 9069
Only Windows uses \
as its file separator.
Thus, the following should result in the wanted behaviour.
@Test
@EnabledOnOs(OS.WINDOWS)
void onlyOnWindows() {
// ...
}
Copied from: https://junit.org/junit5/docs/current/user-guide/#writing-tests-conditional-execution-os
That said, you match a single backslash in Java via 4 (four) backslashes. This should also work:
@EnabledIfSystemProperty(named = "file.separator", matches = "\\\\")
Upvotes: 2