
org.gradle.testing.junit.JUnitLoggingOutputCaptureIntegrationTest.groovy Maven / Gradle / Ivy
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.testing.junit
import org.gradle.integtests.fixtures.HtmlTestExecutionResult
import org.gradle.integtests.fixtures.JUnitXmlTestExecutionResult
import org.gradle.integtests.fixtures.TargetCoverage
import org.gradle.testing.fixture.JUnitMultiVersionIntegrationSpec
import static org.gradle.testing.fixture.JUnitCoverage.*
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.is
// https://github.com/junit-team/junit5/issues/1285
@TargetCoverage({ JUNIT_4_LATEST + emptyIfJava7(JUPITER, VINTAGE) })
class JUnitLoggingOutputCaptureIntegrationTest extends JUnitMultiVersionIntegrationSpec {
def setup() {
buildFile << """
apply plugin: "java"
${mavenCentralRepository()}
dependencies {
testCompile '$dependencyNotation'
}
test {
reports.junitXml.outputPerTestCase = true
// JUnit 5's test name contains paretheses
onOutput { test, event -> print "\${test.toString().replace('()(', '(')} -> \$event.message" }
}
"""
}
def "captures logging output events"() {
file("src/test/java/OkTest.java") << """
public class OkTest {
static {
System.out.println("class loaded");
}
public OkTest() {
System.out.println("test constructed");
}
@org.junit.BeforeClass public static void init() {
System.out.println("before class out");
System.err.println("before class err");
}
@org.junit.AfterClass public static void end() {
System.out.println("after class out");
System.err.println("after class err");
}
@org.junit.Before
public void before() {
System.out.println("before out");
System.err.println("before err");
}
@org.junit.After
public void after() {
System.out.println("after out");
System.err.println("after err");
}
@org.junit.Test
public void ok() {
System.out.print("test out: \u03b1