From d9283d0f2265fbe36759d01f9ae52cd9d3605585 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Tue, 30 Aug 2016 01:25:43 +0200 Subject: [PATCH] Sigh. Fix LoggingTest on Travis When running all tests from gradle, they are executed in a single VM, and from a quick look it is not configurable to start LoggingTest in a separate VM (in order to enforce fresh logback configuration). Thus, previously started tests interfere with the custom logback configuration of LoggingTest. => Set the logback configuration in advance in build.gradle --- app/build.gradle | 7 ++++++- .../gadgetbridge/test/LoggingTest.java | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 84029562..c0ccc260 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,10 +1,15 @@ + apply plugin: 'com.android.application' apply plugin: 'findbugs' apply plugin: 'pmd' def ABORT_ON_CHECK_FAILURE=false -tasks.withType(Test) { systemProperty 'MiFirmwareDir', System.getProperty('MiFirmwareDir', null) } +tasks.withType(Test) { + systemProperty 'MiFirmwareDir', System.getProperty('MiFirmwareDir', null) + systemProperty 'logback.configurationFile', System.getProperty('user.dir', null) + '/app/src/main/assets/logback.xml' + systemProperty 'GB_LOGFILES_DIR', java.nio.file.Files.createTempDirectory('gblog').toString(); +} android { compileOptions { diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LoggingTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LoggingTest.java index e4ff06ec..92315b67 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LoggingTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/LoggingTest.java @@ -39,12 +39,21 @@ public class LoggingTest { @BeforeClass public static void setupSuite() throws Exception { - logFilesDir = FileUtils.createTempDir("logfiles"); - System.setProperty(Logging.PROP_LOGFILES_DIR, logFilesDir.getAbsolutePath()); - File workingDir = new File(System.getProperty("user.dir")); - File configFile = new File(workingDir, "src/main/assets/logback.xml"); - System.out.println(configFile.getAbsolutePath()); - System.setProperty("logback.configurationFile", configFile.getAbsolutePath()); + // properties might be preconfigured in build.gradle because of test ordering problems + String logDir = System.getProperty(Logging.PROP_LOGFILES_DIR); + if (logDir != null) { + logFilesDir = new File(logDir); + } else { + logFilesDir = FileUtils.createTempDir("logfiles"); + System.setProperty(Logging.PROP_LOGFILES_DIR, logFilesDir.getAbsolutePath()); + } + + if (System.getProperty("logback.configurationFile") == null) { + File workingDir = new File(System.getProperty("user.dir")); + File configFile = new File(workingDir, "src/main/assets/logback.xml"); + System.out.println(configFile.getAbsolutePath()); + System.setProperty("logback.configurationFile", configFile.getAbsolutePath()); + } } private Logging logging = new Logging() {