Browse Source

Merged IntegrationTestRunner into TB3Runner

Change-Id: I9e14a75b8446623d8995ee907bd95a1b2452cefd
tags/7.1.13
Artur Signell 10 years ago
parent
commit
5441ef061e

+ 2
- 15
uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java View File

@@ -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());
}

}

+ 0
- 54
uitest/src/com/vaadin/tests/integration/IntegrationTestRunner.java View File

@@ -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);
}
}
}

+ 41
- 3
uitest/src/com/vaadin/tests/tb3/TB3Runner.java View File

@@ -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));
}

}

}

+ 29
- 0
uitest/src/com/vaadin/tests/tb3/TestNameSuffix.java View File

@@ -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();

}

Loading…
Cancel
Save