Created
November 5, 2011 11:00
-
-
Save mike-neck/1341393 to your computer and use it in GitHub Desktop.
The main motief of Lightening Talk (build.gradle to avoid slow test problem) written by @mike_neck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'groovy' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile 'org.codehaus.groovy:groovy:1.8.1' | |
testCompile 'junit:junit:4.9' | |
} | |
task deleteTest { | |
dependsOn << clean | |
'rm /Users/mike/IdeaProjects/GradleSlowTest/src/test/java/orz/mikeneck/gradle/slow/test/*.java'.execute() | |
} | |
task createTest(dependsOn : deleteTest) { | |
'groovy /Users/mike/IdeaProjects/GradleSlowTest/script/CreateTest.groovy'.execute().text.eachLine { line -> | |
println line | |
} | |
} | |
test { | |
maxParallelForks = 4 | |
forkEvery = 20 | |
} | |
task slowTest { | |
dependsOn << createTest | |
dependsOn << test | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by IntelliJ IDEA. | |
* User: mike | |
* Date: 11/11/05 | |
* Time: 15:34 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
import static groovyx.gpars.GParsPool.*; | |
def path = '/Users/mike/IdeaProjects/GradleSlowTest/src/test/java/orz/mikeneck/gradle/slow/test' | |
def packagePath = path.replace('/Users/mike/IdeaProjects/GradleSlowTest/src/test/java/', '') | |
assert new File(path).isDirectory() | |
def head = $/package orz.mikeneck.gradle.slow.test; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.List; | |
import java.util.ArrayList; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
/$ | |
def body =$/ | |
public static final int SIZE = 100; | |
private List<Integer> intList; | |
@Test | |
public void test() throws InterruptedException { | |
int number = 0; | |
for (Integer i : intList) { | |
assertThat(i, is(number++)); | |
Thread.sleep(10); | |
} | |
} | |
@Before | |
public void setUp() { | |
intList = new ArrayList<Integer>(); | |
for (int i = 0; i <= SIZE; i++ ) { | |
intList.add(i); | |
} | |
} | |
} | |
/$ | |
def tests = [] | |
(1..100).each { | |
tests << it | |
} | |
withPool { | |
tests.collectParallel {test -> | |
def className = "GradleTest${test}" | |
def name = "${className}.java" | |
def fileName = "${path}/${name}" | |
def define = "public class ${className} {" | |
def contents = new StringWriter() | |
contents << head | |
contents << define | |
contents << body | |
println '----' | |
println "creating ${fileName}" | |
new File(fileName).write(contents.toString(), 'UTF-8') | |
assert new File(fileName).exists() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment