Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-03-14 06:02:47 -0400
committerCamille Letavernier2014-03-14 06:02:47 -0400
commit51601219900a705ef257c36b6200e1a883c3b956 (patch)
tree138243d07eee415ddc5829c7e78f36be616c87f1 /tests/junit
parentc918e450bb6cd14cf2104d13033571f9d5d46537 (diff)
downloadorg.eclipse.papyrus-51601219900a705ef257c36b6200e1a883c3b956.tar.gz
org.eclipse.papyrus-51601219900a705ef257c36b6200e1a883c3b956.tar.xz
org.eclipse.papyrus-51601219900a705ef257c36b6200e1a883c3b956.zip
430023: [Papyrus Tests] Papyrus shall propose different levels of
testing, to allow test-driven development https://bugs.eclipse.org/bugs/show_bug.cgi?id=430023 - Third implementation, based on a specific TestRunner instead of a MethodRule. The excluded tests are now properly reported as ignored, instead of being successful
Diffstat (limited to 'tests/junit')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationConfig.java3
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRule.java43
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRunner.java49
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractPapyrusTest.java9
4 files changed, 57 insertions, 47 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationConfig.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationConfig.java
index b22bfe95356..302e06314d9 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationConfig.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationConfig.java
@@ -38,6 +38,9 @@ import org.eclipse.papyrus.infra.tools.util.ListHelper;
*
* @author Camille Letavernier
*
+ * @see {@link TestCategory}
+ * @see {@link ClassificationRunner}
+ *
*/
public class ClassificationConfig {
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRule.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRule.java
deleted file mode 100644
index f46248c6654..00000000000
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRule.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.junit.utils.classification;
-
-import org.junit.rules.MethodRule;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.Statement;
-
-/**
- * This rule must be used with Classification annotations
- *
- * @author Camille Letavernier
- *
- * @see {@link InvalidTest}
- * @see {@link NotImplemented}
- *
- */
-public class ClassificationRule implements MethodRule {
-
- public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
- return new Statement() {
-
- @Override
- public void evaluate() throws Throwable {
- if(ClassificationConfig.shouldRun(method.getAnnotations())) {
- System.out.println("Do run");
- base.evaluate();
- } else {
- System.out.println("Skip "+method.getName());
- }
- }
- };
- }
-}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRunner.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRunner.java
new file mode 100644
index 00000000000..34b8867d2cc
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/classification/ClassificationRunner.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.utils.classification;
+
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * A Test Runner which is aware of Classification-related annotations.
+ *
+ * It ignores the test methods according to their annotations, and the policy defined
+ * in {@link ClassificationConfig}
+ *
+ *
+ * @see {@link ClassificationConfig}
+ * @see {@link TestCategory}
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ClassificationRunner extends BlockJUnit4ClassRunner {
+
+ public ClassificationRunner(Class<?> klass) throws InitializationError {
+ super(klass);
+ }
+
+ @Override
+ protected void runChild(FrameworkMethod method, RunNotifier notifier) {
+ if(ClassificationConfig.shouldRun(method.getAnnotations())) {
+ super.runChild(method, notifier);
+ } else {
+ Description description = describeChild(method);
+ notifier.fireTestIgnored(description);
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractPapyrusTest.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractPapyrusTest.java
index bc7309ec510..7e288db0596 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractPapyrusTest.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractPapyrusTest.java
@@ -11,17 +11,18 @@
*****************************************************************************/
package org.eclipse.papyrus.junit.utils.tests;
-import org.eclipse.papyrus.junit.utils.classification.ClassificationRule;
-import org.junit.Rule;
+import org.eclipse.papyrus.junit.utils.classification.ClassificationRunner;
+import org.junit.runner.RunWith;
/**
* An abstract class which should be extended by all Papyrus tests
*
+ * It provides generic support for papyrus-specific annotations (e.g. ClassificationRunner)
+ *
* @author Camille Letavernier
*
*/
+@RunWith(ClassificationRunner.class)
public abstract class AbstractPapyrusTest {
- @Rule
- public final ClassificationRule classification = new ClassificationRule();
}

Back to the top