I'd write a simple custom test runner by extending BlockJUnit4ClassRunner
. That runner would read a configuration from a system property or a configuration file to only run the defined tests. The simplest solution would be a blacklist to exclude selected methods, because the default behaviour of this (default!) runner is to run every test.
Then just say
@RunWith(MyTestRunner.class)
public void TestClass {
// ...
}
For the implementation, it could be sufficiant to just overwrite the getChildren()
method:
@Overwrite
List<FrameworkMethod> getChildren() {
List<FrameworkMethod> fromParent = super.getChildren();
List<FrameworkMethod> filteredList = new ArrayList(filter(fromParent));
return filteredList;
}
where filter checks for every FrameworkMethod
whether it should be executed or not according to the "blacklist", that has been created based on the property.