Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java')
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java37
1 files changed, 34 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java
index 25fb7e5b6..4a7250f03 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SuiteOfTestCases.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,21 +12,25 @@ package org.eclipse.jdt.core.tests.model;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.Set;
+import org.eclipse.test.internal.performance.PerformanceMeterFactory;
+
+import junit.extensions.TestSetup;
import junit.framework.Protectable;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
/**
- * A test case class that can be set up (using the setUpSuite() method) and tore down (using the teardDownSuite() method)
+ * A test case class that can be set up (using the setUpSuite() method) and torn down (using the tearDownSuite() method)
* once for all test cases of this class.
*/
public class SuiteOfTestCases extends org.eclipse.jdt.core.tests.junit.extension.TestCase {
/*
* A test suite that initialize the test case's fields once, then that copies the values
- * of these fields intto each subsequent test case.
+ * of these fields into each subsequent test case.
*/
public static class Suite extends TestSuite {
public SuiteOfTestCases currentTestCase;
@@ -120,4 +124,31 @@ public class SuiteOfTestCases extends org.eclipse.jdt.core.tests.junit.extension
*/
public void tearDownSuite() throws Exception {
}
+
+ /**
+ * Decorate an individual test with setUpSuite/tearDownSuite, so that the test can be run standalone.
+ * This method is called by the Eclipse JUnit test runner when a test is re-run from the JUnit view's context menu.
+ */
+ public static Test setUpTest(Test test) {
+ if (!(test instanceof SuiteOfTestCases))
+ return test;
+
+ final SuiteOfTestCases suiteOfTestCases = (SuiteOfTestCases) test;
+ return new TestSetup(test) {
+ protected void setUp() throws Exception {
+ // reset the PerformanceMeterFactory, so that the same scenario can be run again:
+ Field field = PerformanceMeterFactory.class.getDeclaredField("fScenarios");
+ field.setAccessible(true);
+ Set set = (Set) field.get(null);
+ set.clear();
+
+ suiteOfTestCases.setUpSuite();
+ }
+
+ protected void tearDown() throws Exception {
+ suiteOfTestCases.tearDownSuite();
+ }
+ };
+ }
+
}

Back to the top