下面列出了org.junit.runners.model.FrameworkMethod#getName() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*/
@Override
protected String testName(final FrameworkMethod method) {
String prefix = "";
if (isNotYetImplemented(method) && !isRealBrowser()) {
prefix = "(NYI) ";
}
String browserString = getBrowserVersion().getNickname();
if (isRealBrowser()) {
browserString = "Real " + browserString;
}
final String methodName = method.getName();
if (!maven_) {
return String.format("%s [%s]", methodName, browserString);
}
String className = method.getMethod().getDeclaringClass().getName();
className = className.substring(className.lastIndexOf('.') + 1);
return String.format("%s%s [%s]", prefix, className + '.' + methodName, browserString);
}
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
final Statement statement = super.methodInvoker(method, test);
return new Statement() {
@Override
public void evaluate() throws Throwable {
final String fullyQualifiedTestMethod = test.getClass().getCanonicalName() + "." + method.getName();
final Scenario scenario = testResult.getScenario(method.getName());
currentScenario.put(fullyQualifiedTestMethod, scenario);
if (test instanceof WithTestState) {
TestState testState = ((WithTestState) test).testState();
currentScenario.get(fullyQualifiedTestMethod).setTestState(testState);
}
statement.evaluate();
}
};
}
private JavaBasedTest createJavaBasedTest(FrameworkMethod method) {
String canonicalClassName = method.getDeclaringClass().getCanonicalName();
JavaBasedTest javaBasedTest = new JavaBasedTest(
method.getName() + idGenerator.incrementAndGet(),
method.getName());
WebTauTest webTauTest = javaBasedTest.getTest();
webTauTest.setClassName(canonicalClassName);
webTauTest.setShortContainerId(canonicalClassName);
return javaBasedTest;
}
/**
* Checks if the given {@code dataProviderMethod} is a valid dataprovider and adds a {@link Exception} to
* {@code errors} if it
* <ul>
* <li>is not public,</li>
* <li>is not static,</li>
* <li>takes parameters, or</li>
* <li>does return a convertible type, see {@link DataConverter#canConvert(java.lang.reflect.Type)}
* </ul>
* <p>
* This method is package private (= visible) for testing.
* </p>
*
* @param dataProviderMethod the method to check
* @param dataProvider the {@code @}{@link DataProvider} annotation used on {@code dataProviderMethod}
* @param errors to be "returned" and thrown as {@link InitializationError}
* @throws NullPointerException iif any argument is {@code null}
*/
public void validateDataProviderMethod(FrameworkMethod dataProviderMethod, DataProvider dataProvider,
List<Throwable> errors) {
checkNotNull(dataProviderMethod, "dataProviderMethod must not be null");
checkNotNull(dataProvider, "dataProvider must not be null");
checkNotNull(errors, "errors must not be null");
Method method = dataProviderMethod.getMethod();
String messageBasePart = "Dataprovider method '" + dataProviderMethod.getName() + "' must";
if (!Modifier.isPublic(method.getModifiers())) {
errors.add(new Exception(messageBasePart + " be public"));
}
if (!Modifier.isStatic(method.getModifiers())) {
errors.add(new Exception(messageBasePart + " be static"));
}
if (method.getParameterTypes().length != 0
&& (method.getParameterTypes().length != 1 || !method.getParameterTypes()[0]
.equals(FrameworkMethod.class))) {
errors.add(new Exception(messageBasePart + " either have a single FrameworkMethod parameter or none"));
}
if (!dataConverter.canConvert(method.getGenericReturnType())) {
errors.add(new Exception(messageBasePart
+ " either return Object[][], Object[], String[], Iterable<Iterable<?>>, or Iterable<?>, whereby any subtype of Iterable as well as an arbitrary inner type are also accepted"));
}
if (dataProvider.value().length > 0) {
errors.add(new Exception(messageBasePart + " not define @DataProvider.value()"));
}
}
@Override
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
TestHdfs testHdfsAnnotation = frameworkMethod.getAnnotation(TestHdfs.class);
if (testHdfsAnnotation != null) {
statement = new HdfsStatement(statement, frameworkMethod.getName());
}
return super.apply(statement, frameworkMethod, o);
}
private void writeScreenShotCause(Throwable t, Object test, FrameworkMethod method) throws IOException {
WebDriver driver = injector.getInstance(WebDriver.class);
File file = new File("target/screenshots/"+ test.getClass().getName() + "_" + method.getName() + ".png");
Throwable cause = t.getCause();
boolean fromException = false;
while(cause != null) {
if(cause instanceof ScreenshotException) {
ScreenshotException se = ((ScreenshotException) cause);
byte[] screenshot = Base64.getMimeDecoder().decode(se.getBase64EncodedScreenshot());
Files.createParentDirs(file);
Files.write(screenshot, file);
logger.info("Wrote screenshot to " + file.getAbsolutePath());
fromException = true;
break;
} else {
cause = cause.getCause();
}
}
if(!fromException) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, file);
logger.info("Wrote screenshot to " + file.getAbsolutePath());
}
}
@Override
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
TestHdfs testHdfsAnnotation = frameworkMethod.getAnnotation(TestHdfs.class);
if (testHdfsAnnotation != null) {
statement = new HdfsStatement(statement, frameworkMethod.getName());
}
return super.apply(statement, frameworkMethod, o);
}
protected String getCmmnDefinitionResource(FrameworkMethod method) {
String className = method.getMethod().getDeclaringClass().getName().replace('.', '/');
String methodName = method.getName();
for (String suffix : CmmnDeployer.CMMN_RESOURCE_SUFFIXES) {
String resource = className + "." + methodName + suffix;
if (CmmnTestRunner.class.getClassLoader().getResource(resource) != null) {
return resource;
}
}
return className + "." + method.getName() + ".cmmn";
}
/**
* Flags an error if you have annotated a test with both @Test and @Keys. Any method annotated with @Test will be ignored anyways.
*/
@Override
protected void collectInitializationErrors(final List<Throwable> errors) {
super.collectInitializationErrors(errors);
final List<FrameworkMethod> methodsAnnotatedWithKeys = getTestClass().getAnnotatedMethods(MetaTest.class);
for (final FrameworkMethod frameworkMethod : methodsAnnotatedWithKeys) {
if (frameworkMethod.getAnnotation(Test.class) != null) {
final String gripe = "The method " + frameworkMethod.getName() + "() can only be annotated with @MetaTest";
errors.add(new Exception(gripe));
}
}
}
private static FrameworkMethod getConfigMethod(TestClass testClass) {
List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Config.class);
if (methods.isEmpty()) {
throw new IllegalStateException("@" + Config.class.getSimpleName() + " method not found");
}
if (methods.size() > 1) {
throw new IllegalStateException("Too many @" + Config.class.getSimpleName() + " methods");
}
FrameworkMethod method = methods.get(0);
int modifiers = method.getMethod().getModifiers();
if (!(Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers))) {
throw new IllegalStateException("@" + Config.class.getSimpleName() + " method \"" + method.getName() + "\" must be public static");
}
return method;
}
@Override
protected String testName(FrameworkMethod method)
{
// Eclipse (Helios) can't display results properly if the names
// are not unique.
return method.getName() + getName();
}
@Override
protected String testName( FrameworkMethod pMethod )
{
if( OrcasCoreIntegrationConfigSystemProperties.getOrcasCoreIntegrationConfig().isFlatTestNames() )
{
return getName() + pMethod.getName();
}
else
{
return super.testName( pMethod );
}
}
/**
* {@inheritDoc}
*/
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
final String methodName = frameworkMethod.getName();
final String className = frameworkMethod.getMethod().getDeclaringClass().getName();
if (isExcluded(methodName)) {
return new ExcludedStatement(className, methodName, logger);
} else {
return statement;
}
}
/**
* Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters
*/
@Override
protected String testName(FrameworkMethod method) {
return method.getName() + getName();
}
@Override
protected String testName(FrameworkMethod method) {
return method.getName() + getName();
}
@Override
protected String testName(FrameworkMethod method) {
return method.getName() + ": " + testName;
}
private String getTestInputBaseName(FrameworkMethod method) {
final String basename = method.getAnnotation(TestInput.class).name();
return basename.isEmpty() ? method.getName() : basename;
}
private EndToEndEnvironment getEnvironmentForMethod(FrameworkMethod testMethod) {
String methodName = testMethod.getName();
Optional<EndToEndEnvironment> environment =
this.environmentMap.getOrDefault(methodName, Optional.empty());
return environment.orElse(this.defaultEnv);
}
@Override
protected String testName(final FrameworkMethod method) {
return method.getName() + " - " + getName();
}
@Override
protected String testName(FrameworkMethod method) {
return method.getName() + getName();
}