Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
apply plugin: 'java'
apply plugin: 'eclipse'
ext {
projVersion = '1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
compile group: 'junit', name: 'junit', version: '4.+'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
}
task testCacheSuite(type: Test) {
// task to run a single JUnit test suite
systemProperty 'logback.configurationFile', 'logback.xml'
include '**/SuiteOfTests.class'
testReportDir = file("${reporting.baseDir}/SuiteOfTests")
testResultsDir = file("${buildDir}/test-results/SuiteOfTests")
}
// see build.gradle for imports
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
...
public abstract class Utilities {
public static final Logger logger = LoggerFactory.getLogger( "AnyUniqueStringHere" );
...
public static void printLoggerState() {
// print internal state
LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
}
...
}
public class Test extends Utilities {
@Test
public myTest {
printLoggerState(); // to console
logger.info("Hello World");
}
...
}
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>junit.log</file>
<append>false</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4r %-5level %logger{35}: %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
<!-- We want error logging from this logger to go to an extra appender
It still inherits CONSOLE STDOUT from the root logger -->
<logger name="junit" level="INFO">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
Copy link

ghost commented Apr 28, 2015

I think you forgot to attach the SuiteOfTests.class file?

@felipegutierrez
Copy link

felipegutierrez commented Aug 6, 2021

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment