Skip to content

Commit e8c7265

Browse files
authored
rft test commons (via #1001)
1 parent ffe0fb5 commit e8c7265

File tree

20 files changed

+399
-609
lines changed

20 files changed

+399
-609
lines changed

allure-cucumber4-jvm/src/test/java/io/qameta/allure/cucumber4jvm/AllureCucumber4JvmTest.java

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@
1515
*/
1616
package io.qameta.allure.cucumber4jvm;
1717

18-
import cucumber.runtime.ClassFinder;
1918
import cucumber.runtime.FeaturePathFeatureSupplier;
2019
import cucumber.runtime.Runtime;
2120
import cucumber.runtime.io.MultiLoader;
2221
import cucumber.runtime.io.ResourceLoader;
23-
import cucumber.runtime.io.ResourceLoaderClassFinder;
2422
import cucumber.runtime.model.FeatureLoader;
2523
import io.cucumber.core.model.FeatureWithLines;
2624
import io.cucumber.core.options.CommandlineOptionsParser;
2725
import io.cucumber.core.options.RuntimeOptions;
2826
import io.github.glytching.junit.extension.system.SystemProperty;
2927
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
30-
import io.qameta.allure.AllureLifecycle;
3128
import io.qameta.allure.Step;
3229
import io.qameta.allure.model.Attachment;
3330
import io.qameta.allure.model.FixtureResult;
@@ -41,8 +38,7 @@
4138
import io.qameta.allure.model.TestResult;
4239
import io.qameta.allure.test.AllureFeatures;
4340
import io.qameta.allure.test.AllureResults;
44-
import io.qameta.allure.test.AllureResultsWriterStub;
45-
import io.qameta.allure.test.AllureTestCommonsUtils;
41+
import io.qameta.allure.test.RunUtils;
4642
import org.junit.jupiter.api.Test;
4743
import org.junit.jupiter.api.extension.ExtendWith;
4844
import org.junit.jupiter.api.parallel.ResourceLock;
@@ -719,38 +715,31 @@ void shouldSupportProvidedLabels() {
719715
@Step
720716
private AllureResults runFeature(final String featureResource,
721717
final String... moreOptions) {
722-
723-
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
724-
725-
final AllureLifecycle lifecycle = new AllureLifecycle(writer);
726-
final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
727-
final ClassLoader classLoader = currentThread().getContextClassLoader();
728-
final ResourceLoader resourceLoader = new MultiLoader(classLoader);
729-
final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
730-
final List<String> opts = new ArrayList<>(Arrays.asList(
731-
"--glue", "io.qameta.allure.cucumber4jvm.samples",
732-
"--plugin", "null_summary"
733-
));
734-
opts.addAll(Arrays.asList(moreOptions));
735-
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
736-
final RuntimeOptions options = new CommandlineOptionsParser()
737-
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
738-
739-
final FeaturePathFeatureSupplier supplier
740-
= new FeaturePathFeatureSupplier(new FeatureLoader(resourceLoader), options);
741-
742-
final Runtime runtime = Runtime.builder()
743-
.withClassLoader(classLoader)
744-
.withRuntimeOptions(options)
745-
.withAdditionalPlugins(cucumber4Jvm)
746-
.withFeatureSupplier(supplier)
747-
.build();
748-
749-
runtime.run();
750-
751-
AllureTestCommonsUtils.attach(writer);
752-
753-
return writer;
718+
return RunUtils.runTests(lifecycle -> {
719+
final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
720+
final ClassLoader classLoader = currentThread().getContextClassLoader();
721+
final ResourceLoader resourceLoader = new MultiLoader(classLoader);
722+
final List<String> opts = new ArrayList<>(Arrays.asList(
723+
"--glue", "io.qameta.allure.cucumber4jvm.samples",
724+
"--plugin", "null_summary"
725+
));
726+
opts.addAll(Arrays.asList(moreOptions));
727+
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
728+
final RuntimeOptions options = new CommandlineOptionsParser()
729+
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
730+
731+
final FeaturePathFeatureSupplier supplier
732+
= new FeaturePathFeatureSupplier(new FeatureLoader(resourceLoader), options);
733+
734+
final Runtime runtime = Runtime.builder()
735+
.withClassLoader(classLoader)
736+
.withRuntimeOptions(options)
737+
.withAdditionalPlugins(cucumber4Jvm)
738+
.withFeatureSupplier(supplier)
739+
.build();
740+
741+
runtime.run();
742+
});
754743
}
755744

756745

allure-cucumber5-jvm/src/test/java/io/qameta/allure/cucumber5jvm/AllureCucumber5JvmTest.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.cucumber.core.runtime.TimeServiceEventBus;
2727
import io.github.glytching.junit.extension.system.SystemProperty;
2828
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
29-
import io.qameta.allure.AllureLifecycle;
3029
import io.qameta.allure.Step;
3130
import io.qameta.allure.model.Attachment;
3231
import io.qameta.allure.model.FixtureResult;
@@ -40,8 +39,7 @@
4039
import io.qameta.allure.model.TestResult;
4140
import io.qameta.allure.test.AllureFeatures;
4241
import io.qameta.allure.test.AllureResults;
43-
import io.qameta.allure.test.AllureResultsWriterStub;
44-
import io.qameta.allure.test.AllureTestCommonsUtils;
42+
import io.qameta.allure.test.RunUtils;
4543
import org.junit.jupiter.api.Test;
4644
import org.junit.jupiter.api.extension.ExtendWith;
4745
import org.junit.jupiter.api.parallel.ResourceLock;
@@ -720,38 +718,32 @@ void shouldSupportProvidedLabels() {
720718
@Step
721719
private AllureResults runFeature(final String featureResource,
722720
final String... moreOptions) {
723-
724-
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
725-
726-
final AllureLifecycle lifecycle = new AllureLifecycle(writer);
727-
final AllureCucumber5Jvm cucumber5jvm = new AllureCucumber5Jvm(lifecycle);
728-
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
729-
final List<String> opts = new ArrayList<>(Arrays.asList(
730-
"--glue", "io.qameta.allure.cucumber5jvm.samples",
731-
"--plugin", "null_summary"
732-
));
733-
opts.addAll(Arrays.asList(moreOptions));
734-
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
735-
final RuntimeOptions options = new CommandlineOptionsParser()
736-
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
737-
738-
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
739-
final FeatureParser parser = new FeatureParser(bus::generateId);
740-
final FeaturePathFeatureSupplier supplier
741-
= new FeaturePathFeatureSupplier(classLoader, options, parser);
742-
743-
final Runtime runtime = Runtime.builder()
744-
.withClassLoader(classLoader)
745-
.withRuntimeOptions(options)
746-
.withAdditionalPlugins(cucumber5jvm)
747-
.withFeatureSupplier(supplier)
748-
.build();
749-
750-
runtime.run();
751-
752-
AllureTestCommonsUtils.attach(writer);
753-
754-
return writer;
721+
return RunUtils.runTests(lifecycle -> {
722+
final AllureCucumber5Jvm cucumber5jvm = new AllureCucumber5Jvm(lifecycle);
723+
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
724+
final List<String> opts = new ArrayList<>(Arrays.asList(
725+
"--glue", "io.qameta.allure.cucumber5jvm.samples",
726+
"--plugin", "null_summary"
727+
));
728+
opts.addAll(Arrays.asList(moreOptions));
729+
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
730+
final RuntimeOptions options = new CommandlineOptionsParser()
731+
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
732+
733+
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
734+
final FeatureParser parser = new FeatureParser(bus::generateId);
735+
final FeaturePathFeatureSupplier supplier
736+
= new FeaturePathFeatureSupplier(classLoader, options, parser);
737+
738+
final Runtime runtime = Runtime.builder()
739+
.withClassLoader(classLoader)
740+
.withRuntimeOptions(options)
741+
.withAdditionalPlugins(cucumber5jvm)
742+
.withFeatureSupplier(supplier)
743+
.build();
744+
745+
runtime.run();
746+
});
755747
}
756748

757749

allure-cucumber6-jvm/src/test/java/io/qameta/allure/cucumber6jvm/AllureCucumber6JvmTest.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.cucumber.core.runtime.TimeServiceEventBus;
2727
import io.github.glytching.junit.extension.system.SystemProperty;
2828
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
29-
import io.qameta.allure.AllureLifecycle;
3029
import io.qameta.allure.Step;
3130
import io.qameta.allure.model.Attachment;
3231
import io.qameta.allure.model.FixtureResult;
@@ -40,8 +39,7 @@
4039
import io.qameta.allure.model.TestResult;
4140
import io.qameta.allure.test.AllureFeatures;
4241
import io.qameta.allure.test.AllureResults;
43-
import io.qameta.allure.test.AllureResultsWriterStub;
44-
import io.qameta.allure.test.AllureTestCommonsUtils;
42+
import io.qameta.allure.test.RunUtils;
4543
import org.junit.jupiter.api.Test;
4644
import org.junit.jupiter.api.extension.ExtendWith;
4745
import org.junit.jupiter.api.parallel.ResourceLock;
@@ -720,37 +718,31 @@ void shouldSupportProvidedLabels() {
720718
@Step
721719
private AllureResults runFeature(final String featureResource,
722720
final String... moreOptions) {
723-
724-
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
725-
726-
final AllureLifecycle lifecycle = new AllureLifecycle(writer);
727-
final AllureCucumber6Jvm cucumber6jvm = new AllureCucumber6Jvm(lifecycle);
728-
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
729-
final List<String> opts = new ArrayList<>(Arrays.asList(
730-
"--glue", "io.qameta.allure.cucumber6jvm.samples",
731-
"--plugin", "null_summary"
732-
));
733-
opts.addAll(Arrays.asList(moreOptions));
734-
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
735-
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
736-
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
737-
738-
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
739-
final FeatureParser parser = new FeatureParser(bus::generateId);
740-
final FeaturePathFeatureSupplier supplier
741-
= new FeaturePathFeatureSupplier(classLoader, options, parser);
742-
743-
final Runtime runtime = Runtime.builder()
744-
.withClassLoader(classLoader)
745-
.withRuntimeOptions(options)
746-
.withAdditionalPlugins(cucumber6jvm)
747-
.withFeatureSupplier(supplier)
748-
.build();
749-
750-
runtime.run();
751-
752-
AllureTestCommonsUtils.attach(writer);
753-
754-
return writer;
721+
return RunUtils.runTests(lifecycle -> {
722+
final AllureCucumber6Jvm cucumber6jvm = new AllureCucumber6Jvm(lifecycle);
723+
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
724+
final List<String> opts = new ArrayList<>(Arrays.asList(
725+
"--glue", "io.qameta.allure.cucumber6jvm.samples",
726+
"--plugin", "null_summary"
727+
));
728+
opts.addAll(Arrays.asList(moreOptions));
729+
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
730+
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
731+
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
732+
733+
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
734+
final FeatureParser parser = new FeatureParser(bus::generateId);
735+
final FeaturePathFeatureSupplier supplier
736+
= new FeaturePathFeatureSupplier(classLoader, options, parser);
737+
738+
final Runtime runtime = Runtime.builder()
739+
.withClassLoader(classLoader)
740+
.withRuntimeOptions(options)
741+
.withAdditionalPlugins(cucumber6jvm)
742+
.withFeatureSupplier(supplier)
743+
.build();
744+
745+
runtime.run();
746+
});
755747
}
756748
}

allure-cucumber7-jvm/src/test/java/io/qameta/allure/cucumber7jvm/AllureCucumber7JvmTest.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.cucumber.core.runtime.TimeServiceEventBus;
2727
import io.github.glytching.junit.extension.system.SystemProperty;
2828
import io.github.glytching.junit.extension.system.SystemPropertyExtension;
29-
import io.qameta.allure.AllureLifecycle;
3029
import io.qameta.allure.Step;
3130
import io.qameta.allure.model.Attachment;
3231
import io.qameta.allure.model.FixtureResult;
@@ -40,8 +39,7 @@
4039
import io.qameta.allure.model.TestResult;
4140
import io.qameta.allure.test.AllureFeatures;
4241
import io.qameta.allure.test.AllureResults;
43-
import io.qameta.allure.test.AllureResultsWriterStub;
44-
import io.qameta.allure.test.AllureTestCommonsUtils;
42+
import io.qameta.allure.test.RunUtils;
4543
import org.junit.jupiter.api.Test;
4644
import org.junit.jupiter.api.extension.ExtendWith;
4745
import org.junit.jupiter.api.parallel.ResourceLock;
@@ -721,38 +719,32 @@ void shouldSupportProvidedLabels() {
721719
private AllureResults runFeature(final String featureResource,
722720
final String... moreOptions) {
723721

724-
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
725-
726-
final AllureLifecycle lifecycle = new AllureLifecycle(writer);
727-
final AllureCucumber7Jvm cucumber7jvm = new AllureCucumber7Jvm(lifecycle);
728-
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
729-
final List<String> opts = new ArrayList<>(Arrays.asList(
730-
"--glue", "io.qameta.allure.cucumber7jvm.samples",
731-
"--no-summary"
732-
));
733-
opts.addAll(Arrays.asList(moreOptions));
734-
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
735-
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
736-
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
737-
738-
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
739-
final FeatureParser parser = new FeatureParser(bus::generateId);
740-
final FeaturePathFeatureSupplier supplier
741-
= new FeaturePathFeatureSupplier(classLoader, options, parser);
742-
743-
final Runtime runtime = Runtime.builder()
744-
.withClassLoader(classLoader)
745-
.withRuntimeOptions(options)
746-
.withAdditionalPlugins(cucumber7jvm)
747-
.withFeatureSupplier(supplier)
748-
.build();
749-
750-
runtime.run();
751-
752-
AllureTestCommonsUtils.attach(writer);
753-
754-
return writer;
722+
return RunUtils.runTests(lifecycle -> {
723+
final AllureCucumber7Jvm cucumber7jvm = new AllureCucumber7Jvm(lifecycle);
724+
final Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
725+
final List<String> opts = new ArrayList<>(Arrays.asList(
726+
"--glue", "io.qameta.allure.cucumber7jvm.samples",
727+
"--no-summary"
728+
));
729+
opts.addAll(Arrays.asList(moreOptions));
730+
final FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/" + featureResource);
731+
final RuntimeOptions options = new CommandlineOptionsParser(System.out)
732+
.parse(opts.toArray(new String[]{})).addFeature(featureWithLines).build();
733+
734+
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
735+
final FeatureParser parser = new FeatureParser(bus::generateId);
736+
final FeaturePathFeatureSupplier supplier
737+
= new FeaturePathFeatureSupplier(classLoader, options, parser);
738+
739+
final Runtime runtime = Runtime.builder()
740+
.withClassLoader(classLoader)
741+
.withRuntimeOptions(options)
742+
.withAdditionalPlugins(cucumber7jvm)
743+
.withFeatureSupplier(supplier)
744+
.build();
745+
746+
runtime.run();
747+
});
755748
}
756749

757-
758750
}

0 commit comments

Comments
 (0)