How to use focus method of com.greghaskins.spectrum.internal.Parent class

Best Spectrum code snippet using com.greghaskins.spectrum.internal.Parent.focus

Source:Suite.java Github

copy

Full Screen

...15import java.util.Set;16public class Suite implements Parent, Child {17 private Hooks hooks = new Hooks();18 protected final List<Child> children = new ArrayList<>();19 private final Set<Child> focusedChildren = new HashSet<>();20 private final ChildRunner childRunner;21 private final Description description;22 private final Parent parent;23 private boolean ignored;24 private final TaggingFilterCriteria tagging;25 private BlockConfiguration configuration = BlockConfiguration.defaultConfiguration();26 private NameSanitiser nameSanitiser = new NameSanitiser();27 /**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);...

Full Screen

Full Screen

Source:Configure.java Github

copy

Full Screen

...25 * @param block the enclosed block26 * @return a wrapped block with the given configuration27 * @see #ignore(String)28 * @see #ignore()29 * @see #focus()30 * @see #tags(String...)31 * @see #timeout(Duration)32 */33 static Block with(final BlockConfigurationChain configuration, final Block block) {34 return ConfiguredBlock.with(configuration.getBlockConfiguration(), block);35 }36 /**37 * Mark a block as ignored by surrounding it with the ignore method.38 *39 * @param why explanation of why this block is being ignored40 * @param block the block to ignore41 * @return a wrapped block which will be ignored42 */43 static Block ignore(final String why, final Block block) {44 return with(ignore(why), block);45 }46 /**47 * Mark a block as ignored by surrounding it with the ignore method.48 *49 * @param block the block to ignore50 * @return a wrapped block which will be ignored51 */52 static Block ignore(final Block block) {53 return with(ignore(), block);54 }55 /**56 * Ignore the suite or spec.57 *58 * @return a chainable configuration that will ignore the block within a {@link #with}59 */60 static BlockConfigurationChain ignore() {61 return new BlockConfigurationChain().with(new BlockIgnore());62 }63 /**64 * Ignore the suite or spec.65 *66 * @param reason why this block is ignored67 * @return a chainable configuration that will ignore the block within a {@link #with}68 */69 static BlockConfigurationChain ignore(final String reason) {70 return new BlockConfigurationChain().with(new BlockIgnore(reason));71 }72 /**73 * Tags the suite or spec that is being declared with the given strings. Depending on the current74 * filter criteria, this may lead to the item being ignored during test execution.75 *76 * @param tags tags that relate to the suite or spec77 * @return a chainable configuration that has these tags set for the block in {@link #with}78 */79 static BlockConfigurationChain tags(final String... tags) {80 return new BlockConfigurationChain().with(new BlockTagging(tags));81 }82 /**83 * Marks the suite or spec to be focused.84 *85 * @return a chainable configuration that will focus the suite or spec in the {@link #with}86 */87 static BlockConfigurationChain focus() {88 return new BlockConfigurationChain().with(new BlockFocused());89 }90 /**91 * Apply timeout to all leaf nodes from this level down. Can be superseded by a lower level having its92 * own timeout.93 * @param timeout the amount of the timeout94 * @return a chainable configuration that will apply a timeout to all leaf nodes below95 */96 static BlockConfigurationChain timeout(Duration timeout) {97 return new BlockConfigurationChain().with(new BlockTimeout(timeout));98 }99 /**100 * Filter which tests in the current suite will run.101 *...

Full Screen

Full Screen

Source:Spec.java Github

copy

Full Screen

...35 public int testCount() {36 return 1;37 }38 @Override39 public void focus() {40 if (this.ignored) {41 return;42 }43 this.parent.focus(this);44 }45 @Override46 public void ignore() {47 this.ignored = true;48 }49 @Override50 public boolean isAtomic() {51 return true;52 }53 @Override54 public boolean isLeaf() {55 return true;56 }57 @Override...

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Parent;3import org.junit.Test;4public class Test1 {5 public void test1() {6 Parent parent = new Parent();7 parent.focus();8 }9}10package com.greghaskins.spectrum;11import com.greghaskins.spectrum.internal.Parent;12import org.junit.Test;13public class Test2 {14 public void test2() {15 Parent parent = new Parent();16 parent.focus();17 }18}19 at org.junit.Assert.fail(Assert.java:88)20 at org.junit.Assert.assertTrue(Assert.java:41)21 at org.junit.Assert.assertNotNull(Assert.java:712)22 at org.junit.Assert.assertNotNull(Assert.java:722)23 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:144)24 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:136)25 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:132)26 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:128)27 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:124)28 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:120)29 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:116)30 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:112)31 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:108)32 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:104)33 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:100)34 at com.greghaskins.spectrum.SpectrumTest.assertTestFound(SpectrumTest.java:96)

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1import static com.greghaskins.spectrum.Spectrum.*;2import com.greghaskins.spectrum.Spectrum;3public class 1 {4 public static void main(String[] args) {5 describe("A suite", () -> {6 it("contains spec with an expectation", () -> {7 System.out.println("I am in spec");8 });9 });10 Spectrum.focus("A suite");11 }12}13 at 1.main(1.java:8)14 at java.net.URLClassLoader$1.run(URLClassLoader.java:366)15 at java.net.URLClassLoader$1.run(URLClassLoader.java:355)16 at java.security.AccessController.doPrivileged(Native Method)17 at java.net.URLClassLoader.findClass(URLClassLoader.java:354)18 at java.lang.ClassLoader.loadClass(ClassLoader.java:425)19 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)20 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Parent;3public class Test {4 public static void main(String[] args) {5 Parent root = new Parent();6 Parent parent = new Parent();7 root.addChild(parent);8 parent.focus();9 }10}11package com.greghaskins.spectrum;12import com.greghaskins.spectrum.internal.Parent;13public class Test {14 public static void main(String[] args) {15 Parent root = new Parent();16 Parent parent = new Parent();17 root.addChild(parent);18 root.focus();19 }20}21 at com.greghaskins.spectrum.internal.Parent.focus(Parent.java:91)22 at com.greghaskins.spectrum.Test.main(Test.java:10)

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum.internal;2public class Parent {3 public void focus() {4 System.out.println("Focus on this method");5 }6}7package com.greghaskins.spectrum.internal;8public class Child extends Parent {9 public void focus() {10 System.out.println("Focus on this method");11 }12}13package com.greghaskins.spectrum.internal;14public class Child2 extends Parent {15 public void focus() {16 System.out.println("Focus on this method");17 }18}19package com.greghaskins.spectrum.internal;20public class Child3 extends Parent {21 public void focus() {22 System.out.println("Focus on this method");23 }24}25package com.greghaskins.spectrum.internal;26public class Child4 extends Parent {27 public void focus() {28 System.out.println("Focus on this method");29 }30}31package com.greghaskins.spectrum.internal;32public class Child5 extends Parent {33 public void focus() {34 System.out.println("Focus on this method");35 }36}37package com.greghaskins.spectrum.internal;38public class Child6 extends Parent {39 public void focus() {40 System.out.println("Focus on this method");41 }42}43package com.greghaskins.spectrum.internal;44public class Child7 extends Parent {45 public void focus() {46 System.out.println("Focus on this method");47 }48}

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.Parent;3public class FocusTest {4 public static void main(String[] args) {5 describe("a test", () -> {6 it("is focused", () -> {7 System.out.println("focused test");8 });9 });10 ((Parent) FocusTest.class.getEnclosingClass()).focus();11 new ConsoleRunner().run(FocusTest.class);12 }13}14package com.greghaskins.spectrum;15import com.greghaskins.spectrum.internal.Parent;16public class FocusTest {17 public static void main(String[] args) {18 describe("a test", () -> {19 it("is focused", () -> {20 System.out.println("focused test");21 });22 });23 ((Parent) FocusTest.class.getEnclosingClass()).focus();24 new ConsoleRunner().run(FocusTest.class);25 }26}27package com.greghaskins.spectrum;28import com.greghaskins.spectrum.internal.Parent;29public class FocusTest {30 public static void main(String[] args) {31 describe("a test", () -> {32 it("is focused", () -> {33 System.out.println("focused test");34 });35 });36 ((Parent) FocusTest.class.getEnclosingClass()).focus();37 new ConsoleRunner().run(FocusTest.class);38 }39}40package com.greghaskins.spectrum;41import com.greghaskins.spectrum.internal.Parent;42public class FocusTest {43 public static void main(String[] args) {44 describe("a test", () -> {45 it("is focused", () -> {46 System.out.println("focused test");47 });48 });

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum;2import java.io.File;3import java.io.IOException;4import com.greghaskins.spectrum.internal.Parent;5public class Test {6 public static void main(String[] args) throws IOException {7 Parent focus = new Parent(new File("1.java"));8 focus.focus();9 }10}11package com.greghaskins.spectrum;12import org.junit.Test;13public class Test1 {14 public void test1() {15 System.out.println("test1");16 }17 public void test2() {18 System.out.println("test2");19 }20}21package com.greghaskins.spectrum;22import org.junit.Test;23public class Test2 {24 public void test1() {25 System.out.println("test1");26 }27 public void test2() {28 System.out.println("test2");29 }30}31package com.greghaskins.spectrum;32import org.junit.Test;33public class Test3 {34 public void test1() {35 System.out.println("test1");36 }37 public void test2() {38 System.out.println("test2");39 }40}41package com.greghaskins.spectrum;42import org.junit.Test;43public class Test4 {44 public void test1() {45 System.out.println("test1");46 }47 public void test2() {48 System.out.println("test2");49 }50}51package com.greghaskins.spectrum;52import org.junit.Test;53public class Test5 {54 public void test1() {55 System.out.println("test1");56 }57 public void test2() {58 System.out.println("test2");59 }60}

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1public class ExampleTest {2 public void example() {3 throw new RuntimeException("This test should fail");4 }5}6public class ExampleTest {7 public void example() {8 throw new RuntimeException("This test should pass");9 }10}11public class ExampleTest {12 public void example() {13 throw new RuntimeException("This test should pass");14 }15}16public class ExampleTest {17 public void example() {18 throw new RuntimeException("This test should pass");19 }20}21public class ExampleTest {22 public void example() {23 throw new RuntimeException("This test should pass");24 }25}26public class ExampleTest {27 public void example() {28 throw new RuntimeException("This test should pass");29 }30}31public class ExampleTest {32 public void example() {33 throw new RuntimeException("This test should pass");34 }35}36public class ExampleTest {37 public void example() {38 throw new RuntimeException("This test should pass");39 }40}

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.Spectrum;2import com.greghaskins.spectrum.SpectrumHelper;3import com.greghaskins.spectrum.internal.Parent;4import org.junit.runner.RunWith;5import java.util.Arrays;6import java.util.List;7import static com.greghaskins.spectrum.Spectrum.describe;8import static com.greghaskins.spectrum.Spectrum.it;9@RunWith(Spectrum.class)10public class Test {11 {12 describe("1", () -> {13 it("1", () -> {14 System.out.println("1");15 });16 it("2", () -> {17 System.out.println("2");18 });19 it("3", () -> {20 System.out.println("3");21 });22 it("4", () -> {23 System.out.println("4");24 });25 describe("1.1", () -> {26 it("1", () -> {27 System.out.println("1");28 });29 it("2", () -> {30 System.out.println("2");31 });32 it("3", () -> {33 System.out.println("3");34 });35 it("4", () -> {36 System.out.println("4");37 });38 describe("1.1.1", () -> {

Full Screen

Full Screen

focus

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.*;2import com.greghaskins.spectrum.internal.*;3import java.lang.reflect.*;4import java.util.*;5public class 1 {6 public static void main(String[] args) throws Exception {7 String testMethod = args[0];8 Class<?> c = Class.forName("MyTest");9 Method m = c.getMethod(testMethod);10 Parent p = new Parent(c);11 p.focus(m);12 p.run();13 }14}15import com.greghaskins.spectrum.*;16import static com.greghaskins.spectrum.dsl.specification.Specification.*;17public class MyTest {18 {19 describe("test suite", () -> {20 it("test1", () -> {21 System.out.println("test1");22 });23 it("test2", () -> {24 System.out.println("test2");25 });26 });27 }28}

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.

Run Spectrum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Parent

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful