Reputation: 5605
I am integrating new scala code with an existing system. Our database tests currently are triggered (via Maven and existing IDE configs) by setting the system property "integration". This lets us do this, for example:
mvn test -Dintegration
to include database tests. If we leave off the property, then the tests are skipped. Basically, our existing JUnit tests have (it is a bit cleaner that this, but you'll get the point):
assumeTrue(System.getProperty("integration") != null)
As I'm adding new scala code (NOTE: using JUnitRunner, again so it all just works), and I need to be able to do the equivalent....and I don't want to rebuild my entire infrastructure (continuous integration, etc)...what I'd rather do is write a base trait or something so that I can convert the system property into something that allows me to skip (or include) tests.
Any ideas?
Upvotes: 0
Views: 197
Reputation: 5605
I read the source, and it looks like the JUnitRunner does not even support supplying tags in its current form; however, the code is dead simple, so it turns out the best approach is to copy the code from the existing runner, and modify it to meet my needs.
The following were the requirements due to package permissions, etc.
Other than that, you can simply copy the existing JUnitRunner and modify the run() method to be:
def run(notifier: RunNotifier) {
val ignoreTags = Set("org.scalatest.Ignore") // the built in ignore support
val integrationTags = Set(DbTest.name)
val (tagsToRun, tagsToSkip) =
(if (System.getProperty("integration") == null)
(None, integrationTags ++ ignoreTags)
else
(Some(integrationTags), ignoreTags)
)
try {
suiteToRun.run(None, Args(new RunNotifierReporter(notifier),
Stopper.default, Filter(tagsToRun, tagsToSkip), Map(), None,
new Tracker, Set.empty))
}
catch {
case e: Exception =>
notifier.fireTestFailure(new Failure(getDescription, e))
}
}
Upvotes: 1