Search in sources :

Example 86 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project auto by google.

the class GradleTest method basic.

@Test
public void basic() throws IOException {
    String autoValueVersion = System.getProperty("autoValueVersion");
    assertThat(autoValueVersion).isNotNull();
    String localRepository = System.getProperty("localRepository");
    assertThat(localRepository).isNotNull();
    // Set up the fake Gradle project.
    String buildGradleText = expandSystemProperties(BUILD_GRADLE_TEXT);
    writeFile(fakeProject.newFile("build.gradle").toPath(), buildGradleText);
    Path srcDir = fakeProject.newFolder("src", "main", "java", "com", "example").toPath();
    writeFile(srcDir.resolve("Foo.java"), FOO_TEXT);
    // Build it the first time.
    BuildResult result1 = buildFakeProject();
    assertThat(result1.getOutput()).contains("Full recompilation is required because no incremental change information is" + " available");
    Path output = fakeProject.getRoot().toPath().resolve("build/classes/java/main/com/example/AutoValue_Foo.class");
    assertThat(Files.exists(output)).isTrue();
    // Add a source file to the project.
    String barText = FOO_TEXT.replace("Foo", "Bar");
    Path barFile = srcDir.resolve("Bar.java");
    writeFile(barFile, barText);
    // Build it a second time.
    BuildResult result2 = buildFakeProject();
    assertThat(result2.getOutput()).doesNotContain("Full recompilation is required");
    // Remove the second source file and build a third time. If incremental annotation processing
    // is not working, this will produce a message like this:
    // Full recompilation is required because com.google.auto.value.processor.AutoValueProcessor
    // is not incremental
    Files.delete(barFile);
    BuildResult result3 = buildFakeProject();
    assertThat(result3.getOutput()).doesNotContain("Full recompilation is required");
}
Also used : Path(java.nio.file.Path) BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.Test)

Example 87 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class TestFailuresPluginIntegrationTests method multiProjectContinue.

@Test
void multiProjectContinue() throws IOException {
    createMultiProjectBuild();
    BuildResult result = GradleRunner.create().withDebug(true).withProjectDir(this.projectDir).withArguments("build", "--continue").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 88 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class TestFailuresPluginIntegrationTests method singleProject.

@Test
void singleProject() throws IOException {
    createProject(this.projectDir);
    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:", "", ":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 89 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class OptionalDependenciesPluginIntegrationTests method optionalConfigurationIsCreated.

@Test
void optionalConfigurationIsCreated() throws IOException {
    try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
        out.println("plugins { id 'org.springframework.boot.optional-dependencies' }");
        out.println("task printConfigurations {");
        out.println("    doLast {");
        out.println("        configurations.all { println it.name }");
        out.println("    }");
        out.println("}");
    }
    BuildResult buildResult = runGradle("printConfigurations");
    assertThat(buildResult.getOutput()).contains(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.jupiter.api.Test)

Example 90 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class SpringBootPluginIntegrationTests method failFastWithVersionOfGradle7LowerThanRequired.

@DisabledForJreRange(min = JRE.JAVA_14)
@Test
void failFastWithVersionOfGradle7LowerThanRequired() {
    BuildResult result = this.gradleBuild.gradleVersion("7.3.3").buildAndFail();
    assertThat(result.getOutput()).contains("Spring Boot plugin requires Gradle 7.x (7.4 or later). The current version is Gradle 7.3.3");
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test) DisabledForJreRange(org.junit.jupiter.api.condition.DisabledForJreRange)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)143 File (java.io.File)62 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)20 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 BufferedReader (java.io.BufferedReader)4