Gradle allows me to start multiple jvms for testing like so:
test {
maxParallelForks = 10
}
Some of the tests for an application I have requires a fake ftp server which needs a port. This is quite easy to do with one jvm:
test {
systemProperty 'ftpPort', 10000
}
However, when running in parallel I would need to start 10 fake ftp servers. How do I add a custom system property for each jvm spawned by gradle?
Something like:
test {
maxParallelForks 10
customizeForks { index ->
systemProperty 'ftpPort', 10000 + index
}
}
There's no setup task to do before an after the fork. However, you can override the test task in your project to achieve the behavior (here in Java), as the Test task is simply a class:
public class ForkTest extends org.gradle.api.tasks.testing.Test {
private final AtomicInteger nextPort = new AtomicInteger(10000);
public Test copyTo(JavaForkOptions target) {
super.copyTo(target);
target.systemProperty("ftpPort", nextPort.getAndAIncrement());
return this;
}
}
Then in your build.gradle :
task testFork(Type: ForkTest){
forkEvery = 1
maxParallelForks = 10
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With