org.spockframework.runtime.model.SpecInfo Java Examples

The following examples show how to use org.spockframework.runtime.model.SpecInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 5 votes vote down vote up
private TestContext buildContext(IMethodInvocation invocation, Throwable exception) {
    return new TestContext(
        applicationContext,
        Optional.ofNullable(invocation.getSpec()).map(SpecInfo::getReflection).orElse(null),
        Optional.ofNullable(invocation.getFeature()).map(FeatureInfo::getFeatureMethod).map(MethodInfo::getReflection).orElse(null),
        invocation.getInstance(),
        exception);
}
 
Example #2
Source File: AllureSpockTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
protected AllureResults run(final Class<?> clazz) {
    final AllureResultsWriterStub results = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(results);

    final RunNotifier notifier = new RunNotifier();
    final SpecInfo spec = new SpecInfoBuilder(clazz).build();
    spec.addListener(new AllureSpock(lifecycle));

    new JUnitDescriptionGenerator(spec).describeSpecMethods();
    new JUnitDescriptionGenerator(spec).describeSpec();

    final AllureLifecycle cached = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);

        RunContext.get().createSpecRunner(spec, notifier).run();
    } catch (Exception e) {
        throw new RuntimeException("could not execute sample", e);
    } finally {
        Allure.setLifecycle(cached);
        StepsAspects.setLifecycle(cached);
        AttachmentsAspects.setLifecycle(cached);
    }

    return results;
}
 
Example #3
Source File: LoggingTestExtension.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Override
public void visitSpecAnnotation(LogTestInformation annotation, SpecInfo spec) {
	for (FeatureInfo feature : spec.getFeatures()) {
		if (!feature.getFeatureMethod().getReflection().isAnnotationPresent(LogTestInformation.class)) {
			intercept(annotation, feature.getFeatureMethod());
		}
	}
}
 
Example #4
Source File: GuiceyInterceptor.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
public GuiceyInterceptor(final SpecInfo spec, final EnvironmentSupport support,
                         final List<GuiceyConfigurationHook> hooks) {
    this.support = support;
    this.hooks = hooks;
    injectionPoints = InjectionPoint.forInstanceMethodsAndFields(spec.getReflection());
    clientFields = SpecialFieldsSupport.findClientFields(spec.getReflection());
}
 
Example #5
Source File: AbstractAppExtension.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public void visitSpec(final SpecInfo spec) {
    final Class<?> testType = spec.getReflection();
    final List<GuiceyConfigurationHook> hooks = SpecialFieldsSupport.findHooks(testType);
    hooks.addAll(HooksUtil.create(getHooks(annotation)));
    final GuiceyInterceptor interceptor =
            new GuiceyInterceptor(spec, buildSupport(annotation, testType), hooks);
    final SpecInfo topSpec = spec.getTopSpec();
    topSpec.addSharedInitializerInterceptor(interceptor);
    topSpec.addInitializerInterceptor(interceptor);
    topSpec.addCleanupSpecInterceptor(interceptor);
}
 
Example #6
Source File: GuiceyConfigurationExtension.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public void visitSpec(final SpecInfo spec) {
    final GuiceyConfigurationHookInterceptor interceptor =
            new GuiceyConfigurationHookInterceptor(HooksUtil.create(confs));
    // hook interceptor MUST go first, otherwise guicey will start without these changes
    spec.getTopSpec().getSharedInitializerInterceptors().add(0, interceptor);
    spec.getTopSpec().addCleanupSpecInterceptor(interceptor);
}
 
Example #7
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 4 votes vote down vote up
@Override
public void visitSpec(SpecInfo spec) {
    // no-op
}
 
Example #8
Source File: AllureSpock.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void visitSpec(final SpecInfo spec) {
    spec.addListener(this);
}
 
Example #9
Source File: AllureSpock.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeIteration(final IterationInfo iteration) {
    final String uuid = testResults.get();
    final FeatureInfo feature = iteration.getFeature();
    final SpecInfo spec = feature.getSpec();
    final List<Parameter> parameters = getParameters(feature.getDataVariables(), iteration.getDataValues());
    final SpecInfo subSpec = spec.getSubSpec();
    final SpecInfo superSpec = spec.getSuperSpec();
    final String packageName = spec.getPackage();
    final String specName = spec.getName();
    final String testClassName = feature.getDescription().getClassName();
    final String testMethodName = iteration.getName();

    final List<Label> labels = new ArrayList<>(Arrays.asList(
            createPackageLabel(packageName),
            createTestClassLabel(testClassName),
            createTestMethodLabel(testMethodName),
            createSuiteLabel(specName),
            createHostLabel(),
            createThreadLabel(),
            createFrameworkLabel("spock"),
            createLanguageLabel("java")
    ));
    if (Objects.nonNull(subSpec)) {
        labels.add(createSubSuiteLabel(subSpec.getName()));
    }
    if (Objects.nonNull(superSpec)) {
        labels.add(createParentSuiteLabel(superSpec.getName()));
    }
    labels.addAll(getLabels(iteration));
    labels.addAll(getProvidedLabels());

    final TestResult result = new TestResult()
            .setUuid(uuid)
            .setHistoryId(getHistoryId(getQualifiedName(iteration), parameters))
            .setName(firstNonEmpty(
                    testMethodName,
                    feature.getDescription().getDisplayName(),
                    getQualifiedName(iteration)).orElse("Unknown"))
            .setFullName(getQualifiedName(iteration))
            .setStatusDetails(new StatusDetails()
                    .setFlaky(isFlaky(iteration))
                    .setMuted(isMuted(iteration)))
            .setParameters(parameters)
            .setLinks(getLinks(iteration))
            .setLabels(labels);
    processDescription(iteration, result);
    getLifecycle().scheduleTestCase(result);
    getLifecycle().startTestCase(uuid);
}
 
Example #10
Source File: AllureSpock.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private <T extends Annotation> List<T> getSpecAnnotations(final IterationInfo iteration, final Class<T> clazz) {
    final SpecInfo spec = iteration.getFeature().getSpec();
    return getAnnotationsOnClass(spec.getDescription(), clazz);
}
 
Example #11
Source File: AbstractAppExtension.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
public void visitSpecAnnotation(final T useApplication, final SpecInfo spec) {
    this.annotation = useApplication;
}
 
Example #12
Source File: GuiceyConfigurationExtension.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
public void visitSpecAnnotation(final UseGuiceyHooks annotation, final SpecInfo spec) {
    confs = annotation.value();
}