diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-03-27 13:52:46 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-03-28 08:55:13 +0000 |
commit | 3775a7ff907bdf59a1007ba61c97d8548b6e4535 (patch) | |
tree | eaf1ab7875537cc479abf49ed874810842e7c99c /uitest/src/com/vaadin/tests/tb3 | |
parent | 29e7df26ad034eacdbf37fc03985873aabda6576 (diff) | |
download | vaadin-framework-3775a7ff907bdf59a1007ba61c97d8548b6e4535.tar.gz vaadin-framework-3775a7ff907bdf59a1007ba61c97d8548b6e4535.zip |
Added categories inclusion and exclusion feature to TB3TestSuite.
Added test category annotation.
Added default values for properties.
Added categories to tests.
Change-Id: I04259f1e56a75eb8c9834c125f44cb375196ddf8
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
4 files changed, 73 insertions, 14 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTestWithProxy.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTestWithProxy.java index 1a1e507a4a..d600b5fef2 100755 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTestWithProxy.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTestWithProxy.java @@ -24,7 +24,9 @@ import org.junit.Before; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; +import com.vaadin.tests.annotations.TestCategory; +@TestCategory("push") public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest { private static AtomicInteger availablePort = new AtomicInteger(2000); diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 18a2b69025..8b536858e5 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -35,6 +35,7 @@ import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; import org.openqa.selenium.remote.DesiredCapabilities; +import com.vaadin.tests.annotations.TestCategory; import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil; import com.vaadin.tests.tb3.AbstractTB3Test.RunLocally; @@ -77,14 +78,20 @@ public class TB3Runner extends BlockJUnit4ClassRunner { try { AbstractTB3Test testClassInstance = getTestClassInstance(); - Collection<DesiredCapabilities> desiredCapabilites = getDesiredCapabilities(testClassInstance); + Collection<DesiredCapabilities> desiredCapabilities = getDesiredCapabilities(testClassInstance); TestNameSuffix testNameSuffixProperty = findAnnotation( testClassInstance.getClass(), TestNameSuffix.class); for (FrameworkMethod m : getTestMethods()) { - if (desiredCapabilites.size() > 0) { - for (DesiredCapabilities capabilities : desiredCapabilites) { + // No browsers available for this test, so we need to + // wrap the test method inside IgnoredTestMethod. + // This will add @Ignore annotation to it. + if (desiredCapabilities.size() <= 0 + || categoryIsExcludedOrNotExcplicitlyIncluded()) { + tests.add(new IgnoredTestMethod(m.getMethod())); + } else { + for (DesiredCapabilities capabilities : desiredCapabilities) { TB3Method method = new TB3Method(m.getMethod(), capabilities); if (testNameSuffixProperty != null) { @@ -94,12 +101,6 @@ public class TB3Runner extends BlockJUnit4ClassRunner { } tests.add(method); } - - } else { - // No browsers available for this test, so we need to - // wrap the test method inside IgnoredTestMethod. - // This will add @Ignore annotation to it. - tests.add(new IgnoredTestMethod(m.getMethod())); } } } catch (Exception e) { @@ -109,6 +110,60 @@ public class TB3Runner extends BlockJUnit4ClassRunner { return tests; } + private boolean categoryIsExcludedOrNotExcplicitlyIncluded() { + Class<?> c = getTestClass().getJavaClass(); + + if (categoryIsExcluded(c)) { + return true; + } + + if (explicitInclusionIsUsed()) { + return !categoryIsIncluded(c); + } + + return false; + } + + private boolean categoryIsIncluded(Class<?> c) { + String include = System.getProperty("categories.include"); + if (include != null && include.trim().length() > 0) { + return hasCategoryFor(c, include.toLowerCase().trim()); + } + + return false; + } + + private static boolean explicitInclusionIsUsed() { + String include = System.getProperty("categories.include"); + + return include != null && include.trim().length() > 0; + } + + private static boolean categoryIsExcluded(Class<?> c) { + String exclude = System.getProperty("categories.exclude"); + if (exclude != null && exclude.trim().length() > 0) { + return hasCategoryFor(c, exclude.toLowerCase().trim()); + } + + return false; + } + + private static boolean hasCategoryFor(Class<?> c, String searchString) { + if (hasCategory(c)) { + return searchString.contains(getCategory(c).toLowerCase()); + } + + return false; + } + + private static boolean hasCategory(Class<?> c) { + return c.getAnnotation(TestCategory.class) != null; + } + + private static String getCategory(Class<?> c) { + return c.getAnnotation(TestCategory.class).value(); + } + private List<FrameworkMethod> getTestMethods() { return getTestClass().getAnnotatedMethods(Test.class); } @@ -150,16 +205,16 @@ public class TB3Runner extends BlockJUnit4ClassRunner { for (DesiredCapabilities d : desiredCapabilites) { String browserName = (d.getBrowserName() + d.getVersion()) .toLowerCase(); - if (include != null) { - if (include.toLowerCase().contains(browserName)) { + if (include != null && include.trim().length() > 0) { + if (include.trim().toLowerCase().contains(browserName)) { filteredCapabilities.add(d); } } else { filteredCapabilities.add(d); } - if (exclude != null) { - if (exclude.toLowerCase().contains(browserName)) { + if (exclude != null && exclude.trim().length() > 0) { + if (exclude.trim().toLowerCase().contains(browserName)) { filteredCapabilities.remove(d); } } diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java index 5878e8ab15..60bdb53083 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java @@ -246,7 +246,7 @@ public class TB3TestSuite extends Suite { if (c.getAnnotation(ExcludeFromSuite.class) != null) { return false; } + return true; } - }
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java index e9ef11957c..69a06a561a 100644 --- a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java +++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java @@ -25,6 +25,7 @@ import java.util.List; import org.openqa.selenium.remote.DesiredCapabilities; +import com.vaadin.tests.annotations.TestCategory; import com.vaadin.tests.tb3.MultiBrowserTest.Browser; /** @@ -33,6 +34,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser; * * @author Vaadin Ltd */ +@TestCategory("push") public abstract class WebsocketTest extends PrivateTB3Configuration { private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>(); static { |