lttng: Correctly skip tests if test traces are missing
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 22 Jul 2014 22:57:19 +0000 (18:57 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 23 Jul 2014 15:24:58 +0000 (11:24 -0400)
It used to be "unsafe" to do assumeTrue() in @BeforeClass methods,
but since Luna it seems to be the other way around: it skips
correctly when put in an @BeforeClass, but results in a failure
if it's within a @Before. Makes perfect sense!

Now add this to abstract and extending test classes, both with
different @BeforeClass, and you get a recipe for disaster.

Change-Id: I83670475241325f2e0277055fad83d8943927624
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/30298

org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/analysis/LttngKernelAnalysisTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/event/matchandsync/ExperimentSyncTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/PartialStateSystemTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemInMemoryTest.java
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java

index 073ba850806ef896647a10b9b8ba0a9bc2588ff9..e63a907da07d5cc7430acb3b56cdb1d9b0769d69 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableSet;
@@ -49,13 +50,20 @@ public class LttngKernelAnalysisTest {
     private ITmfTrace fTrace;
     private LttngKernelAnalysisModule fKernelAnalysisModule;
 
+    /**
+     * Class setup
+     */
+    @BeforeClass
+    public static void setUpClass() {
+        assumeTrue(CtfTmfTestTrace.KERNEL.exists());
+    }
+
     /**
      * Set-up the test
      */
     @Before
     public void setUp() {
         fKernelAnalysisModule = new LttngKernelAnalysisModule();
-        assumeTrue(CtfTmfTestTrace.KERNEL.exists());
         fTrace = CtfTmfTestTrace.KERNEL.getTrace();
     }
 
index 11af64a3993f6cf39c3610a1b3abc31f17a74c13..8ee0bf3714678c22a43db120865481a4b46dffa6 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -46,13 +47,19 @@ public class ExperimentSyncTest {
     private static TmfExperiment fExperiment;
 
     /**
-     * Setup the traces and experiment
+     * Class setup
      */
-    @Before
-    public void setUp() {
+    @BeforeClass
+    public static void setUpClass() {
         assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
         assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
+    }
 
+    /**
+     * Setup the traces and experiment
+     */
+    @Before
+    public void setUp() {
         fTraces = new CtfTmfTrace[2];
         fTraces[0] = CtfTmfTestTrace.SYNC_SRC.getTrace();
         fTraces[1] = CtfTmfTestTrace.SYNC_DEST.getTrace();
index 50fcf6ca91a89c14c44d3cddbcb42db56c146de4..448a2d2b23a16ac49c7f1a6fda5fbad9c2bcf002 100644 (file)
@@ -30,8 +30,8 @@ import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -43,15 +43,15 @@ public class PartialStateSystemTest extends StateSystemTest {
 
     private static final @NonNull String TEST_FILE_NAME = "test-partial";
 
-    private static File stateFile;
-    private static TestLttngKernelAnalysisModule module;
+    private File stateFile;
+    private TestLttngKernelAnalysisModule module;
 
 
     /**
      * Initialization
      */
-    @BeforeClass
-    public static void initialize() {
+    @Before
+    public void initialize() {
         assumeTrue(testTrace.exists());
         stateFile = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + TEST_FILE_NAME);
         if (stateFile.exists()) {
@@ -74,8 +74,8 @@ public class PartialStateSystemTest extends StateSystemTest {
     /**
      * Class clean-up
      */
-    @AfterClass
-    public static void tearDownClass() {
+    @After
+    public void tearDownClass() {
         module.close();
         stateFile.delete();
     }
index b9801240b422669f65dff54f0932e2940adb75f0..88f5c3e9f592371415849f525d05446d214c1faa 100644 (file)
@@ -17,7 +17,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
 
 import java.io.File;
 
@@ -32,8 +31,8 @@ import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -47,16 +46,15 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
     private static final @NonNull String TEST_FILE_NAME = "test.ht";
     private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht";
 
-    private static File stateFile;
-    private static File stateFileBenchmark;
-    private static TestLttngKernelAnalysisModule module;
+    private File stateFile;
+    private File stateFileBenchmark;
+    private TestLttngKernelAnalysisModule module;
 
     /**
      * Initialize the test cases (build the history file once for all tests).
      */
-    @BeforeClass
-    public static void initialize() {
-        assumeTrue(testTrace.exists());
+    @Before
+    public void initialize() {
         stateFile = createStateFile(TEST_FILE_NAME);
         stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
 
@@ -76,8 +74,8 @@ public class StateSystemFullHistoryTest extends StateSystemTest {
     /**
      * Clean-up
      */
-    @AfterClass
-    public static void tearDownClass() {
+    @After
+    public void tearDownClass() {
         module.close();
         stateFile.delete();
         stateFileBenchmark.delete();
index 8cb40fbaf71f1a3940cde1f11d55943342aa208e..393c112634e23065b0e206e65ca4c7705ba06fe5 100644 (file)
@@ -24,8 +24,8 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
 
 /**
  * State system tests using the in-memory back-end.
@@ -34,13 +34,13 @@ import org.junit.BeforeClass;
  */
 public class StateSystemInMemoryTest extends StateSystemTest {
 
-    private static TestLttngKernelAnalysisModule module;
+    private TestLttngKernelAnalysisModule module;
 
     /**
      * Initialization
      */
-    @BeforeClass
-    public static void initialize() {
+    @Before
+    public void initialize() {
         assumeTrue(testTrace.exists());
 
         module = new TestLttngKernelAnalysisModule();
@@ -58,8 +58,8 @@ public class StateSystemInMemoryTest extends StateSystemTest {
     /**
      * Class cleanup
      */
-    @AfterClass
-    public static void cleanupClass() {
+    @After
+    public void cleanupClass() {
         module.close();
     }
 
index 21d9b41b2c69d24099cc5398c87e7dc84070c6cd..711a00c58b085ae2428511e4e4d3a818ccdf5689 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.util.List;
 
@@ -27,6 +28,7 @@ import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
 import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -55,6 +57,14 @@ public abstract class StateSystemTest {
     /* Offset in the trace + start time of the trace */
     static final long interestingTimestamp1 = 18670067372290L + 1331649577946812237L;
 
+    /**
+     * Class set-up
+     */
+    @BeforeClass
+    public static void setUpClass() {
+        assumeTrue(testTrace.exists());
+    }
+
     @Test
     public void testFullQuery1() {
         List<ITmfStateInterval> list;
This page took 0.030565 seconds and 5 git commands to generate.