Search in sources :

Example 21 with BuildResult

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);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 22 with BuildResult

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");
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 23 with BuildResult

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()", "");
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test)

Example 24 with BuildResult

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()", "");
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test)

Example 25 with BuildResult

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");
    }
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) FileWriter(java.io.FileWriter) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) PrintWriter(java.io.PrintWriter) TestTemplate(org.junit.jupiter.api.TestTemplate)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)149 File (java.io.File)65 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)21 StringWriter (java.io.StringWriter)19 GradleRunner (org.gradle.testkit.runner.GradleRunner)17 Test (org.testng.annotations.Test)10 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)8 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TestHelpers.findFile (me.tatarka.TestHelpers.findFile)6 TestHelpers.writeFile (me.tatarka.TestHelpers.writeFile)6 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 Path (java.nio.file.Path)5 BuildTask (org.gradle.testkit.runner.BuildTask)5