Skip to content

Commit

Permalink
rft test commons (via #1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jan 31, 2024
1 parent ffe0fb5 commit e8c7265
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
*/
package io.qameta.allure.cucumber4jvm;

import cucumber.runtime.ClassFinder;
import cucumber.runtime.FeaturePathFeatureSupplier;
import cucumber.runtime.Runtime;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.io.ResourceLoaderClassFinder;
import cucumber.runtime.model.FeatureLoader;
import io.cucumber.core.model.FeatureWithLines;
import io.cucumber.core.options.CommandlineOptionsParser;
import io.cucumber.core.options.RuntimeOptions;
import io.github.glytching.junit.extension.system.SystemProperty;
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.Step;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.FixtureResult;
Expand All @@ -41,8 +38,7 @@
import io.qameta.allure.model.TestResult;
import io.qameta.allure.test.AllureFeatures;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.test.AllureResultsWriterStub;
import io.qameta.allure.test.AllureTestCommonsUtils;
import io.qameta.allure.test.RunUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.ResourceLock;
Expand Down Expand Up @@ -719,38 +715,31 @@ void shouldSupportProvidedLabels() {
@Step
private AllureResults runFeature(final String featureResource,
final String... moreOptions) {

final AllureResultsWriterStub writer = new AllureResultsWriterStub();

final AllureLifecycle lifecycle = new AllureLifecycle(writer);
final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
final ClassLoader classLoader = currentThread().getContextClassLoader();
final ResourceLoader resourceLoader = new MultiLoader(classLoader);
final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber4jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser()
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(new FeatureLoader(resourceLoader), options);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber4Jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();

AllureTestCommonsUtils.attach(writer);

return writer;
return RunUtils.runTests(lifecycle -> {
final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
final ClassLoader classLoader = currentThread().getContextClassLoader();
final ResourceLoader resourceLoader = new MultiLoader(classLoader);
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber4jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser()
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(new FeatureLoader(resourceLoader), options);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber4Jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.github.glytching.junit.extension.system.SystemProperty;
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.Step;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.FixtureResult;
Expand All @@ -40,8 +39,7 @@
import io.qameta.allure.model.TestResult;
import io.qameta.allure.test.AllureFeatures;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.test.AllureResultsWriterStub;
import io.qameta.allure.test.AllureTestCommonsUtils;
import io.qameta.allure.test.RunUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.ResourceLock;
Expand Down Expand Up @@ -720,38 +718,32 @@ void shouldSupportProvidedLabels() {
@Step
private AllureResults runFeature(final String featureResource,
final String... moreOptions) {

final AllureResultsWriterStub writer = new AllureResultsWriterStub();

final AllureLifecycle lifecycle = new AllureLifecycle(writer);
final AllureCucumber5Jvm cucumber5jvm = new AllureCucumber5Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber5jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser()
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber5jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();

AllureTestCommonsUtils.attach(writer);

return writer;
return RunUtils.runTests(lifecycle -> {
final AllureCucumber5Jvm cucumber5jvm = new AllureCucumber5Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber5jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser()
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber5jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.github.glytching.junit.extension.system.SystemProperty;
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.Step;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.FixtureResult;
Expand All @@ -40,8 +39,7 @@
import io.qameta.allure.model.TestResult;
import io.qameta.allure.test.AllureFeatures;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.test.AllureResultsWriterStub;
import io.qameta.allure.test.AllureTestCommonsUtils;
import io.qameta.allure.test.RunUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.ResourceLock;
Expand Down Expand Up @@ -720,37 +718,31 @@ void shouldSupportProvidedLabels() {
@Step
private AllureResults runFeature(final String featureResource,
final String... moreOptions) {

final AllureResultsWriterStub writer = new AllureResultsWriterStub();

final AllureLifecycle lifecycle = new AllureLifecycle(writer);
final AllureCucumber6Jvm cucumber6jvm = new AllureCucumber6Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber6jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber6jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();

AllureTestCommonsUtils.attach(writer);

return writer;
return RunUtils.runTests(lifecycle -> {
final AllureCucumber6Jvm cucumber6jvm = new AllureCucumber6Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber6jvm.samples",
"--plugin", "null_summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber6jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.github.glytching.junit.extension.system.SystemProperty;
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.Step;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.FixtureResult;
Expand All @@ -40,8 +39,7 @@
import io.qameta.allure.model.TestResult;
import io.qameta.allure.test.AllureFeatures;
import io.qameta.allure.test.AllureResults;
import io.qameta.allure.test.AllureResultsWriterStub;
import io.qameta.allure.test.AllureTestCommonsUtils;
import io.qameta.allure.test.RunUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.ResourceLock;
Expand Down Expand Up @@ -721,38 +719,32 @@ void shouldSupportProvidedLabels() {
private AllureResults runFeature(final String featureResource,
final String... moreOptions) {

final AllureResultsWriterStub writer = new AllureResultsWriterStub();

final AllureLifecycle lifecycle = new AllureLifecycle(writer);
final AllureCucumber7Jvm cucumber7jvm = new AllureCucumber7Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber7jvm.samples",
"--no-summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber7jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();

AllureTestCommonsUtils.attach(writer);

return writer;
return RunUtils.runTests(lifecycle -> {
final AllureCucumber7Jvm cucumber7jvm = new AllureCucumber7Jvm(lifecycle);
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
final List<String> opts = new ArrayList<>(Arrays.asList(
"--glue", "io.qameta.allure.cucumber7jvm.samples",
"--no-summary"
));
opts.addAll(Arrays.asList(moreOptions));
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();

final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final FeatureParser parser = new FeatureParser(bus::generateId);
final FeaturePathFeatureSupplier supplier
= new FeaturePathFeatureSupplier(classLoader, options, parser);

final Runtime runtime = Runtime.builder()
.withClassLoader(classLoader)
.withRuntimeOptions(options)
.withAdditionalPlugins(cucumber7jvm)
.withFeatureSupplier(supplier)
.build();

runtime.run();
});
}


}
Loading

0 comments on commit e8c7265

Please sign in to comment.