How to use runChild method of com.greghaskins.spectrum.internal.Suite class

Best Spectrum code snippet using com.greghaskins.spectrum.internal.Suite.runChild

Source:Suite.java Github

copy

Full Screen

...28 * The strategy for running the children within the suite.29 */30 @FunctionalInterface31 interface ChildRunner {32 void runChildren(final Suite suite, final RunReporting<Description, Failure> reporting);33 }34 public static Suite rootSuite(final Description description) {35 return new Suite(description, Parent.NONE, Suite::defaultChildRunner,36 new TaggingFilterCriteria());37 }38 /**39 * Constructs a suite.40 *41 * @param description the JUnit description42 * @param parent parent item43 * @param childRunner which child running strategy to use - this will normally be44 * {@link #defaultChildRunner(Suite, RunReporting)} which runs them all but can be45 * substituted.46 * @param taggingFilterCriteria the state of tagging inherited from the parent47 */48 protected Suite(final Description description, final Parent parent, final ChildRunner childRunner,49 final TaggingFilterCriteria taggingFilterCriteria) {50 this.description = description;51 this.parent = parent;52 this.ignored = parent.isIgnored();53 this.childRunner = childRunner;54 this.tagging = taggingFilterCriteria;55 }56 public Suite addSuite(final String name) {57 return addSuite(name, Suite::defaultChildRunner);58 }59 private Suite addSuite(final String name, final ChildRunner childRunner) {60 final Suite suite = new Suite(Description.createSuiteDescription(sanitise(name)), this, childRunner,61 this.tagging.clone());62 suite.inheritConfigurationFromParent(configuration.forChild());63 return addedToThis(suite);64 }65 private Suite addedToThis(Suite suite) {66 addChild(suite);67 return suite;68 }69 public Suite addCompositeSuite(final String name) {70 final Suite suite =71 new CompositeTest(Description.createSuiteDescription(sanitise(name)), this,72 this.tagging.clone());73 return addedToThis(suite);74 }75 public Child addSpec(final String name, final Block block) {76 final Child spec = createSpec(name, block);77 addChild(spec);78 return spec;79 }80 private Child createSpec(final String name, final Block block) {81 final Description specDescription =82 Description.createTestDescription(this.description.getClassName(), sanitise(name));83 return configuredChild(new Spec(specDescription, block, this), block);84 }85 private void inheritConfigurationFromParent(final BlockConfiguration fromParent) {86 configuration = merge(fromParent, configuration);87 }88 private Child configuredChild(final Child child, final Block block) {89 merge(this.configuration.forChild(), ConfiguredBlock.configurationFromBlock(block))90 .applyTo(child, this.tagging);91 return child;92 }93 public void applyConfigurationFromBlock(Block block) {94 this.configuration = merge(this.configuration, ConfiguredBlock.configurationFromBlock(block));95 this.configuration.applyTo(this, this.tagging);96 }97 private void addChild(final Child child) {98 this.children.add(child);99 }100 /**101 * Adds a hook to be the first one executed before the block. This is the default. Hooks should be102 * executed in the order they are declared in the test.103 *104 * @param hook to add105 */106 public void addHook(final HookContext hook) {107 this.hooks.add(hook);108 }109 private Hooks getHooksFor(final Child child) {110 Hooks allHooks = this.parent.getInheritableHooks().plus(this.hooks);111 return child.isAtomic() ? allHooks.forAtomic() : allHooks.forNonAtomic();112 }113 @Override114 public Hooks getInheritableHooks() {115 // only the atomic hooks can be used by the children of this suite,116 // all other hooks would be executed at suite level only - either for117 // each child of the suite, or once118 return this.parent.getInheritableHooks().plus(this.hooks.forAtomic());119 }120 /**121 * Set the suite to require certain tags of all tests below.122 *123 * @param tags required tags - suites must have at least one of these if any are specified124 */125 public void includeTags(final String... tags) {126 this.tagging.include(tags);127 }128 /**129 * Set the suite to exclude certain tags of all tests below.130 *131 * @param tags excluded tags - suites and specs must not have any of these if any are specified132 */133 public void excludeTags(final String... tags) {134 this.tagging.exclude(tags);135 }136 @Override137 public void focus(final Child child) {138 this.focusedChildren.add(child);139 focus();140 }141 @Override142 public void focus() {143 if (this.ignored) {144 return;145 }146 this.parent.focus(this);147 }148 @Override149 public void ignore() {150 this.ignored = true;151 }152 @Override153 public boolean isIgnored() {154 return this.ignored;155 }156 @Override157 public void run(final RunReporting<Description, Failure> reporting) {158 if (testCount() == 0) {159 reporting.fireTestIgnored(this.description);160 runChildren(reporting);161 } else {162 runSuite(reporting);163 }164 }165 private void runSuite(final RunReporting<Description, Failure> reporting) {166 if (isEffectivelyIgnored()) {167 runChildren(reporting);168 } else {169 this.hooks.once().sorted()170 .runAround(this.description, reporting, () -> runChildren(reporting));171 }172 }173 private void runChildren(final RunReporting<Description, Failure> reporting) {174 this.childRunner.runChildren(this, reporting);175 }176 protected void runChild(final Child child, final RunReporting<Description, Failure> reporting) {177 if (child.isEffectivelyIgnored()) {178 // running the child will make it act ignored179 child.run(reporting);180 } else if (childIsNotInFocus(child)) {181 reporting.fireTestIgnored(child.getDescription());182 } else {183 addLeafHook(this.hooks.forThisLevel().sorted(), child).runAround(child.getDescription(), reporting,184 () -> runChildWithHooks(child, reporting));185 }186 }187 private boolean childIsNotInFocus(Child child) {188 return !this.focusedChildren.isEmpty() && !this.focusedChildren.contains(child);189 }190 private void runChildWithHooks(final Child child, final RunReporting<Description, Failure> reporting) {191 getHooksFor(child).sorted().runAround(child.getDescription(), reporting,192 () -> child.run(reporting));193 }194 private Hooks addLeafHook(final Hooks hooks, final Child child) {195 if (child.isLeaf()) {196 hooks.add(testNotifier());197 }198 return hooks;199 }200 private HookContext testNotifier() {201 return new HookContext(testNotificationHook(), 0, HookContext.AppliesTo.ONCE,202 HookContext.Precedence.ROOT);203 }204 private Hook testNotificationHook() {205 return (description, notifier, block) -> {206 notifier.fireTestStarted(description);207 try {208 block.run();209 } finally {210 notifier.fireTestFinished(description);211 }212 };213 }214 @Override215 public Description getDescription() {216 final Description copy = this.description.childlessCopy();217 this.children.forEach((child) -> copy.addChild(child.getDescription()));218 return copy;219 }220 @Override221 public int testCount() {222 return this.children.stream().mapToInt(Child::testCount).sum();223 }224 public void removeAllChildren() {225 this.children.clear();226 }227 private static void defaultChildRunner(final Suite suite,228 final RunReporting<Description, Failure> reporting) {229 suite.children.forEach((child) -> suite.runChild(child, reporting));230 }231 private String sanitise(final String name) {232 return this.nameSanitiser.sanitise(name);233 }234 @Override235 public boolean isEffectivelyIgnored() {236 return this.ignored || !hasANonIgnoredChild();237 }238 private boolean hasANonIgnoredChild() {239 return this.children.stream()240 .anyMatch(child -> !child.isEffectivelyIgnored());241 }242}...

Full Screen

Full Screen

Source:CompositeTest.java Github

copy

Full Screen

...28 for (Child child : suite.children) {29 if (decoratedReporting.hasFailedYet()) {30 child.ignore();31 }32 suite.runChild(child, decoratedReporting);33 }34 }35}...

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Suite;3import java.util.ArrayList;4import java.util.Collection;5import java.util.List;6import java.util.function.Supplier;7import org.junit.runner.Description;8import org.junit.runner.Runner;9import org.junit.runner.notification.RunNotifier;10public class TestRunner extends Runner {11 private final Description description;12 private final List<Runner> children = new ArrayList<>();13 public TestRunner(Class<?> testClass) {14 description = Description.createSuiteDescription(testClass);15 children.add(new Suite(testClass));16 }17 public Description getDescription() {18 return description;19 }20 public void run(RunNotifier notifier) {21 children.forEach(child -> child.run(notifier));22 }23 public void filter(Filter filter) throws NoTestsRemainException {24 children.forEach(child -> child.filter(filter));25 }26 public void sort(Sorter sorter) {27 children.forEach(child -> child.sort(sorter));28 }29 public String toString() {30 return description.toString();31 }32 public void visit(TestClassVisitor visitor) {33 children.forEach(child -> child.visit(visitor));34 }35 public List<Runner> getChildren() {36 return children;37 }38 public void runChild(Runner runner, RunNotifier notifier) {39 children.forEach(child -> child.runChild(runner, notifier));40 }41 public Description describeChild(Runner runner) {42 return children.get(0).describeChild(runner);43 }44 public void setScheduler(RunnerScheduler scheduler) {45 children.forEach(child -> child.setScheduler(scheduler));46 }47 public void setSchedulerSupplier(Supplier<RunnerScheduler> schedulerSupplier) {48 children.forEach(child -> child.setSchedulerSupplier(schedulerSupplier));49 }50 public void collectInitializationErrors(Collection<Throwable> errors) {51 children.forEach(child -> child.collectInitializationErrors(errors));52 }53 public void collectErrors(Collection<Throwable> errors) {54 children.forEach(child -> child.collectErrors(errors));55 }56}

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.*;2import com.greghaskins.spectrum.internal.*;3import com.greghaskins.spectrum.internal.configuration.*;4import com.greghaskins.spectrum.internal.hooks.*;5import com.greghaskins.spectrum.internal.hooks.Hook;6import com.greghaskins.spectrum.internal.hooks.HookContext;7import com.greghaskins.spectrum.internal.hooks.HookScope;8import com.greghaskins.spectrum.internal.hooks.HookType;9import com.greghaskins.spectrum.internal.hooks.Hookable;10import com.greghaskins.spectrum.internal.hooks.Hooks;11import com.greghaskins.spectrum.internal.hooks.HooksFactory;12import com.greghaskins.spectrum.internal.hooks.HooksFactory.HookLifecycle;13import com.greghaskins.spectrum.internal.hooks.HooksFactory.HookLifecycleType;14import com.greghaskins.spectrum.internal.hooks.HooksFactory.HookType;15import com.greghaskins.spectrum.internal.hooks.HooksFactory.HookableType;16import com.greghaskins.spectrum.internal.hooks.HooksFactory.SpecificationHookLifecycleType;17import com.greghaskins.spectrum.internal.hooks.HooksFactory.SpecificationHookType;18import com.greghaskins.spectrum.internal.hooks.HooksFactory.SuiteHookLifecycleType;19import com.greghaskins.spectrum.internal.hooks.HooksFactory.SuiteHookType;20import com.greghaskins.spectrum.internal.hooks.HooksFactory.SuiteLifecycleType;21import com.greghaskins.spectrum.internal.hooks.HooksFactory.SuiteType;22import com.greghaskins.spectrum.internal.junit.*;23import com.greghaskins.spectrum.internal.junit.JUnitLifecycle;24import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.JUnitLifecycleType;25import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.JUnitType;26import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.SpecificationLifecycleType;27import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.SpecificationType;28import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.SuiteLifecycleType;29import com.greghaskins.spectrum.internal.junit.JUnitLifecycle.Suite

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import java.util.ArrayList;3import java.util.List;4import com.greghaskins.spectrum.internal.Suite;5public class ChildRunnerTest {6 public static void main(String[] args) {7 List<Class<?>> children = new ArrayList<>();8 children.add(SuiteTest.class);9 children.add(SuiteTest.class);10 Suite.runChildren(children);11 }12}13package com.greghaskins.spectrum;14import java.util.ArrayList;15import java.util.List;16import com.greghaskins.spectrum.internal.Suite;17public class ChildRunnerTest {18 public static void main(String[] args) {19 List<Class<?>> children = new ArrayList<>();20 children.add(SuiteTest.class);21 children.add(SuiteTest.class);22 Suite.runChildren(children);23 }24}25package com.greghaskins.spectrum;26import java.util.ArrayList;27import java.util.List;28import com.greghaskins.spectrum.internal.Suite;29public class ChildRunnerTest {30 public static void main(String[] args) {31 List<Class<?>> children = new ArrayList<>();32 children.add(SuiteTest.class);33 children.add(SuiteTest.class);34 Suite.runChildren(children);35 }36}37package com.greghaskins.spectrum;38import java.util.ArrayList;39import java.util.List;40import com.greghaskins.spectrum.internal.Suite;41public class ChildRunnerTest {42 public static void main(String[] args) {43 List<Class<?>> children = new ArrayList<>();44 children.add(SuiteTest.class);45 children.add(SuiteTest.class);46 Suite.runChildren(children);47 }48}49package com.greghaskins.spectrum;50import java.util.ArrayList;51import java.util.List;52import com.greghaskins.spectrum.internal.Suite;53public class ChildRunnerTest {54 public static void main(String[] args) {

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Suite;3public class RunChildSuite {4 public static void main(String[] args) {5 Suite suite = new Suite("parent suite", () -> {6 Suite childSuite = new Suite("child suite", () -> {7 });8 suite.runChild(childSuite);9 });10 suite.run();11 }12}13package com.greghaskins.spectrum;14import com.greghaskins.spectrum.internal.Suite;15public class RunChildTest {16 public static void main(String[] args) {17 Suite suite = new Suite("parent suite", () -> {18 Suite childSuite = new Suite("child suite", () -> {19 });20 childSuite.runChild(new Suite("child test", () -> {21 }));22 });23 suite.run();24 }25}26package com.greghaskins.spectrum;27import com.greghaskins.spectrum.internal.Suite;28public class RunChildSuiteWithChildTest {29 public static void main(String[] args) {30 Suite suite = new Suite("parent suite", () -> {31 Suite childSuite = new Suite("child suite", () -> {32 });33 childSuite.runChild(new Suite("child test", () -> {34 }));35 suite.runChild(childSuite);36 });37 suite.run();38 }39}40package com.greghaskins.spectrum;41import com.greghaskins.spectrum.internal.Suite;

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum.internal;2import com.greghaskins.spectrum.Suite;3public class Test1 {4 public static void main(String[] args) {5 Suite suite = new Suite("Test1");6 suite.runChild(new Suite("Test2"));7 }8}9package com.greghaskins.spectrum.internal;10import com.greghaskins.spectrum.Suite;11public class Test2 {12 public static void main(String[] args) {13 Suite suite = new Suite("Test2");14 suite.runChild(new Suite("Test3"));15 }16}17package com.greghaskins.spectrum.internal;18import com.greghaskins.spectrum.Suite;19public class Test3 {20 public static void main(String[] args) {21 Suite suite = new Suite("Test3");22 suite.runChild(new Suite("Test4"));23 }24}25package com.greghaskins.spectrum.internal;26import com.greghaskins.spectrum.Suite;27public class Test4 {28 public static void main(String[] args) {29 Suite suite = new Suite("Test4");30 suite.runChild(new Suite("Test5"));31 }32}33package com.greghaskins.spectrum.internal;34import com.greghaskins.spectrum.Suite;35public class Test5 {36 public static void main(String[] args) {37 Suite suite = new Suite("Test5");38 suite.runChild(new Suite("Test6"));39 }40}41package com.greghaskins.spectrum.internal;

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Suite;3public class ChildClass extends Suite {4public static void main(String[] args) {5Suite.runChild(ChildClass.class);6}7}8package com.greghaskins.spectrum;9import com.greghaskins.spectrum.internal.Suite;10public class ChildClass2 extends Suite {11public static void main(String[] args) {12Suite.runChild(ChildClass2.class);13}14}15package com.greghaskins.spectrum;16import com.greghaskins.spectrum.internal.Suite;17public class ChildClass3 extends Suite {18public static void main(String[] args) {19Suite.runChild(ChildClass3.class);20}21}22package com.greghaskins.spectrum;23import com.greghaskins.spectrum.internal.Suite;24public class ChildClass4 extends Suite {25public static void main(String[] args) {26Suite.runChild(ChildClass4.class);27}28}29package com.greghaskins.spectrum;30import com.greghaskins.spectrum.internal.Suite;31public class ChildClass5 extends Suite {32public static void main(String[] args) {33Suite.runChild(ChildClass5.class);34}35}36package com.greghaskins.spectrum;37import com.greghaskins.spectrum.internal.Suite;38public class ChildClass6 extends Suite {39public static void main(String[] args) {40Suite.runChild(ChildClass6.class);41}42}

Full Screen

Full Screen

runChild

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 Suite suite = new Suite();4 Description description = suite.createSuiteDescription(2.class, "2");5 suite.runChild(2.class, description);6 }7}8public class 2 {9 public void run(RunNotifier notifier) {10 Suite suite = new Suite();11 suite.run(notifier);12 }13}14public class 3 {15 public void run(RunNotifier notifier) {16 Suite suite = new Suite();17 suite.run(notifier);18 }19}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful