use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.
the class AndroidFeaturePluginTest method unitTest.
@Test
public void unitTest() throws Exception {
writeFile(buildFile, // language="Groovy"
"buildscript {\n" + " repositories {\n" + " maven { url 'https://maven.google.com' }\n" + " jcenter()\n" + " }\n" + " \n" + " dependencies {\n" + " classpath files(" + getPluginClasspath() + ")\n" + " classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + " }\n" + "}\n" + "\n" + "apply plugin: 'com.android.feature'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + " maven { url 'https://maven.google.com' }\n" + " mavenCentral()\n" + " jcenter()\n" + "}\n" + "\n" + "android {\n" + " compileSdkVersion " + compileSdkVersion + "\n" + " buildToolsVersion '" + buildToolsVersion + "'\n" + " \n" + " defaultConfig {\n" + " minSdkVersion 15\n" + " targetSdkVersion 24\n" + " }\n" + "}\n" + "\n" + "dependencies {\n" + " testCompile 'junit:junit:4.12'\n" + "}");
File manifestFile = new File(rootDir, "src/main/AndroidManifest.xml");
writeFile(manifestFile, // language="XML"
"<manifest package=\"test.test\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + " <application/>\n" + "</manifest>");
File javaFile = new File(rootDir, "src/main/java/Main.java");
writeFile(javaFile, "import java.util.concurrent.Callable;\n" + "\n" + "public class Main {\n" + " public static Callable<String> f() {\n" + " return () -> \"Hello, Lambda Test!\";\n" + " }\n" + "}");
File testJavaFile = new File(rootDir, "src/test/java/Test.java");
writeFile(testJavaFile, "import org.junit.Assert;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.JUnit4;\n" + "\n" + "import java.util.concurrent.Callable;\n" + "\n" + "@RunWith(JUnit4.class)\n" + "public class Test {\n" + " @org.junit.Test\n" + " public void test() throws Exception {\n" + " Runnable lambda = () -> Assert.assertTrue(true);\n" + " lambda.run();\n" + " Assert.assertEquals(\"Hello, Lambda Test!\", Main.f().call());\n" + " }\n" + "}");
StringWriter errorOutput = new StringWriter();
BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("test", "--stacktrace").forwardStdError(errorOutput).build();
assertThat(result.task(":test").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class OptionalDependenciesPluginIntegrationTests method optionalDependenciesAreAddedToSourceSetClasspath.
private void optionalDependenciesAreAddedToSourceSetClasspath(String sourceSet, String classpath) throws IOException {
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
out.println("plugins {");
out.println(" id 'org.springframework.boot.optional-dependencies'");
out.println(" id 'java'");
out.println("}");
out.println("repositories {");
out.println(" mavenCentral()");
out.println("}");
out.println("dependencies {");
out.println(" optional 'org.springframework:spring-jcl:5.1.2.RELEASE'");
out.println("}");
out.println("task printClasspath {");
out.println(" doLast {");
out.println(" println sourceSets." + sourceSet + "." + classpath + ".files");
out.println(" }");
out.println("}");
}
BuildResult buildResult = runGradle("printClasspath");
assertThat(buildResult.getOutput()).contains("spring-jcl");
}
use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class TestFailuresPluginIntegrationTests method multiProjectParallel.
@Test
void multiProjectParallel() throws IOException {
createMultiProjectBuild();
BuildResult result = GradleRunner.create().withDebug(true).withProjectDir(this.projectDir).withArguments("build", "--parallel", "--stacktrace").withPluginClasspath().buildAndFail();
assertThat(readLines(result.getOutput())).containsSequence("Found test failures in 2 test tasks:", "", ":project-one:test", " example.ExampleTests > bad()", " example.ExampleTests > fail()", " example.MoreTests > bad()", " example.MoreTests > fail()", "", ":project-two:test", " example.ExampleTests > bad()", " example.ExampleTests > fail()", " example.MoreTests > bad()", " example.MoreTests > fail()", "");
}
use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class TestFailuresPluginIntegrationTests method multiProject.
@Test
void multiProject() throws IOException {
createMultiProjectBuild();
BuildResult result = GradleRunner.create().withDebug(true).withProjectDir(this.projectDir).withArguments("build").withPluginClasspath().buildAndFail();
assertThat(readLines(result.getOutput())).containsSequence("Found test failures in 1 test task:", "", ":project-one:test", " example.ExampleTests > bad()", " example.ExampleTests > fail()", " example.MoreTests > bad()", " example.MoreTests > fail()", "");
}
use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.
the class AbstractBootArchiveIntegrationTests method classesFromASecondarySourceSetCanBeIncludedInTheArchive.
@TestTemplate
void classesFromASecondarySourceSetCanBeIncludedInTheArchive() throws IOException {
writeMainClass();
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/secondary/java/example");
examplePackage.mkdirs();
File main = new File(examplePackage, "Secondary.java");
try (PrintWriter writer = new PrintWriter(new FileWriter(main))) {
writer.println("package example;");
writer.println();
writer.println("public class Secondary {}");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
BuildResult build = this.gradleBuild.build(this.taskName);
assertThat(build.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
Stream<String> classesEntryNames = jarFile.stream().filter((entry) -> !entry.isDirectory()).map(JarEntry::getName).filter((name) -> name.startsWith(this.classesPath));
assertThat(classesEntryNames).containsExactly(this.classesPath + "example/Main.class", this.classesPath + "example/Secondary.class");
}
}
Aggregations