diff options
author | Artur Signell <artur@vaadin.com> | 2014-02-20 22:56:43 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-03-17 06:43:24 +0000 |
commit | 5441ef061e4b3bf1f6545f829121bcefcb256ef9 (patch) | |
tree | 3ff9a89afb70270fe7f6a53e393c8b61a6b0dc19 | |
parent | 0c7cbc73dba97ad0b95cb11f4b4eabb37046fe61 (diff) | |
download | vaadin-framework-5441ef061e4b3bf1f6545f829121bcefcb256ef9.tar.gz vaadin-framework-5441ef061e4b3bf1f6545f829121bcefcb256ef9.zip |
Merged IntegrationTestRunner into TB3Runner
Change-Id: I9e14a75b8446623d8995ee907bd95a1b2452cefd
4 files changed, 72 insertions, 72 deletions
diff --git a/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java b/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java index cbb3a8b8e4..0266a9d892 100644 --- a/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java +++ b/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java @@ -15,15 +15,8 @@ */ package com.vaadin.tests.integration; -import java.util.Collection; -import java.util.Collections; - -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized.Parameters; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.tests.tb3.MultiBrowserTest.Browser; import com.vaadin.tests.tb3.PrivateTB3Configuration; +import com.vaadin.tests.tb3.TestNameSuffix; /** * Base class for integration tests. Integration tests use the @@ -32,7 +25,7 @@ import com.vaadin.tests.tb3.PrivateTB3Configuration; * * @author Vaadin Ltd */ -@RunWith(IntegrationTestRunner.class) +@TestNameSuffix(property = "server-name") public abstract class AbstractIntegrationTest extends PrivateTB3Configuration { @Override protected String getBaseURL() { @@ -41,13 +34,7 @@ public abstract class AbstractIntegrationTest extends PrivateTB3Configuration { throw new RuntimeException( "Deployment url must be given as deployment.url"); } - return deploymentUrl; } - @Parameters - public static Collection<DesiredCapabilities> getBrowsersForTest() { - return Collections.singleton(Browser.FIREFOX.getDesiredCapabilities()); - } - } diff --git a/uitest/src/com/vaadin/tests/integration/IntegrationTestRunner.java b/uitest/src/com/vaadin/tests/integration/IntegrationTestRunner.java deleted file mode 100644 index f5042b54b6..0000000000 --- a/uitest/src/com/vaadin/tests/integration/IntegrationTestRunner.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.tests.integration; - -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; - -import com.vaadin.tests.tb3.TB3Runner; - -/** - * JUnit runner for integration tests. Replaces the actual method name with the - * server-name property when generating the test name. - * - * @author Vaadin Ltd - */ -public class IntegrationTestRunner extends TB3Runner { - - private Class<?> testClass; - - public IntegrationTestRunner(Class<?> klass) throws InitializationError { - super(klass); - testClass = klass; - } - - /* - * (non-Javadoc) - * - * @see - * org.junit.runners.BlockJUnit4ClassRunner#testName(org.junit.runners.model - * .FrameworkMethod) - */ - @Override - protected String testName(FrameworkMethod method) { - if (AbstractIntegrationTest.class.isAssignableFrom(testClass)) { - return System.getProperty("server-name"); - } else { - return super.testName(method); - } - } -} diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index eaffa80d09..54bb2d86a5 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -16,6 +16,7 @@ package com.vaadin.tests.tb3; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; @@ -83,12 +84,21 @@ public class TB3Runner extends BlockJUnit4ClassRunner { .getAnnotation(RunLocally.class).value() .getDesiredCapabilities()); } - for (DesiredCapabilities capabilities : desiredCapabilites) { + TestNameSuffix testNameSuffixProperty = findAnnotation( + testClassInstance.getClass(), TestNameSuffix.class); + for (DesiredCapabilities capabilities : desiredCapabilites) { // Find any methods marked with @Test. for (FrameworkMethod m : getTestClass().getAnnotatedMethods( Test.class)) { - tests.add(new TB3Method(m.getMethod(), capabilities)); + TB3Method method = new TB3Method(m.getMethod(), + capabilities); + if (testNameSuffixProperty != null) { + method.setTestNameSuffix("-" + + System.getProperty(testNameSuffixProperty + .property())); + } + tests.add(method); } } } catch (Exception e) { @@ -98,6 +108,27 @@ public class TB3Runner extends BlockJUnit4ClassRunner { return tests; } + /** + * Finds the given annotation in the given class or one of its super + * classes. Return the first found annotation + * + * @param searchClass + * @param annotationClass + * @return + */ + private <T extends Annotation> T findAnnotation(Class<?> searchClass, + Class<T> annotationClass) { + if (searchClass == Object.class) { + return null; + } + + if (searchClass.getAnnotation(annotationClass) != null) { + return searchClass.getAnnotation(annotationClass); + } + + return findAnnotation(searchClass.getSuperclass(), annotationClass); + } + /* * (non-Javadoc) * @@ -141,12 +172,17 @@ public class TB3Runner extends BlockJUnit4ClassRunner { private static class TB3Method extends FrameworkMethod { private DesiredCapabilities capabilities; + private String testNameSuffix = ""; public TB3Method(Method method, DesiredCapabilities capabilities) { super(method); this.capabilities = capabilities; } + public void setTestNameSuffix(String testNameSuffix) { + this.testNameSuffix = testNameSuffix; + } + @Override public Object invokeExplosively(final Object target, Object... params) throws Throwable { @@ -156,9 +192,11 @@ public class TB3Runner extends BlockJUnit4ClassRunner { @Override public String getName() { - return String.format("%s[%s]", getMethod().getName(), + return String.format("%s[%s]", getMethod().getName() + + testNameSuffix, BrowserUtil.getUniqueIdentifier(capabilities)); } } + } diff --git a/uitest/src/com/vaadin/tests/tb3/TestNameSuffix.java b/uitest/src/com/vaadin/tests/tb3/TestNameSuffix.java new file mode 100644 index 0000000000..9f9bb07a13 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/TestNameSuffix.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.tb3; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Defines a system property to be used as part of the test name + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface TestNameSuffix { + + String property(); + +} |