How can I disable tests when required any required system property is missing?

57 views Asked by At

I wrote my test class which requires three system properties provided.

Currently I'm trying with this.

// all three system properties should be specified!
@DisabledIfSystemProperty(named = "some, matches = "^\\s+$")
@DisabledIfSystemProperty(named = "other, matches = "^\\s+$")
@DisabledIfSystemProperty(named = "another, matches = "^\\s+$")
class MyTest {
}

It seems not work. How can I disable the MyTest class when any of these required system properties is missing?

In contrast, How can I enable the MyTest class when all of these system properties are specified?

1

There are 1 answers

1
Jin Kwon On

Oh... annotations work as expected.

Originally, I tried to put those annotation on my abstract parent test class.

@DisabledIfSystemProperty(named = "some, matches = "^\\s*$")
@DisabledIfSystemProperty(named = "other, matches = "^\\s*$")
@DisabledIfSystemProperty(named = "another, matches = "^\\s*$")
abstract class MyTest {
}

An I jsut found,

This annotation is not @Inherited. Consequently, if you wish to apply the same semantics to a subclass, this annotation must be redeclared on the subclass.

I should put them on each subclass.

abstract class MyTest {
}

@DisabledIfSystemProperty(named = "some, matches = "^\\s*$")
@DisabledIfSystemProperty(named = "other, matches = "^\\s*$")
@DisabledIfSystemProperty(named = "another, matches = "^\\s*$")
class YourTest extends MyTest {
}