How to use Child class of NSpec.Tests.ClassContextBug package

Best NSpec code snippet using NSpec.Tests.ClassContextBug.Child

Run NSpec automation tests on LambdaTest cloud grid

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

NestContextsTests.cs

Source: NestContextsTests.cs Github

copy
1using System.Collections.Generic;
2using System.Reflection;
3using NSpec.Domain;
4using NSpec.Domain.Formatters;
5using NUnit.Framework;
6
7namespace NSpec.Tests.ClassContextBug
8{
9    public class NestContextsTests
10    {
11        public void debug()
12        {
13            //the specification class you want to test
14            //this can be a regular expression
15            var testClassYouWantToDebug = "NSpec.Tests.ClassContextBug.Child";
16
17            //initialize NSpec's specfinder
18            var finder = new SpecFinder(
19                new Reflector(typeof(NestContextsTests).GetTypeInfo().Assembly.Location),
20                testClassYouWantToDebug);
21
22            //initialize NSpec's builder
23            var builder = new ContextBuilder(finder, new DefaultConventions());
24
25            //this line runs the tests you specified in the filter
26            var noTagsFilter = new Tags();
27            TestFormatter formatter = new TestFormatter();
28            new ContextRunner(noTagsFilter, formatter, false).Run(builder.Contexts().Build());
29
30            Context grandParent = formatter.Contexts[0];
31            Assert.That(grandParent.Name, Is.EqualTo("Grand Parent"));
32            Assert.That(grandParent.Contexts.Count, Is.EqualTo(2));
33            Assert.That(grandParent.Contexts[0].Name, Is.EqualTo("Grand Parent Context"));
34            Assert.That(grandParent.Contexts[1].Name, Is.EqualTo("Parent"));
35            Assert.That(grandParent.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand Parent!!!\""));
36            Assert.That(grandParent.Contexts[0].Examples[0].Exception, Is.Null);
37            Assert.That(grandParent.Contexts[0].Examples[0].Pending, Is.False);
38
39            Context parent = formatter.Contexts[0].Contexts[1];
40            Assert.That(parent.Name, Is.EqualTo("Parent"));
41            Assert.That(parent.Contexts.Count, Is.EqualTo(2));
42            Assert.That(parent.Contexts[0].Name, Is.EqualTo("Parent Context"));
43            Assert.That(parent.Contexts[1].Name, Is.EqualTo("Child"));
44            Assert.That(parent.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand [email protected]@@\""));
45            Assert.That(parent.Contexts[0].Examples[0].Exception, Is.Null);
46            Assert.That(parent.Contexts[0].Examples[0].Pending, Is.False);
47
48            Context child = formatter.Contexts[0].Contexts[1].Contexts[1];
49            Assert.That(child.Name, Is.EqualTo("Child"));
50            Assert.That(child.Contexts.Count, Is.EqualTo(1));
51            Assert.That(child.Contexts[0].Name, Is.EqualTo("Child Context"));
52            Assert.That(child.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand [email protected]@@###\""));
53            Assert.That(child.Contexts[0].Examples[0].Exception, Is.Null);
54            Assert.That(child.Contexts[0].Examples[0].Pending, Is.False);
55        }
56    }
57
58    public class TestFormatter : IFormatter
59    {
60        public ContextCollection Contexts { get; set; }
61
62        public void Write(ContextCollection contexts)
63        {
64            this.Contexts = contexts;
65        }
66
67        public IDictionary<string, string> Options { get; set; }
68    }
69}
Full Screen

NestedContexts.cs

Source: NestedContexts.cs Github

copy
1using NUnit.Framework;
2
3namespace NSpec.Tests.ClassContextBug
4{
5    class Grand_Parent : nspec
6    {
7        public string TestValue;
8
9        void before_each()
10        {
11            this.TestValue = "Grand Parent";
12        }
13
14        void act_each()
15        {
16            this.TestValue = this.TestValue + "!!!";
17        }
18
19        void Grand_Parent_Context()
20        {
21            it["TestValue should be \"Grand Parent!!!\""] = () => Assert.That(TestValue, Is.EqualTo("Grand Parent!!!"));
22        }
23    }
24
25    class Parent : Grand_Parent
26    {
27        void before_each()
28        {
29            this.TestValue += "." + "Parent";
30        }
31
32        void act_each()
33        {
34            this.TestValue = this.TestValue + "@@@";
35        }
36
37        void Parent_Context()
38        {
39            it["TestValue should be \"Grand [email protected]@@\""] = () => Assert.That(TestValue, Is.EqualTo("Grand [email protected]@@"));
40        }
41    }
42
43    class Child : Parent
44    {
45        void before_each()
46        {
47            this.TestValue += "." + "Child";
48        }
49
50        void act_each()
51        {
52            this.TestValue = this.TestValue + "###";
53        }
54
55        void Child_Context()
56        {
57            it["TestValue should be \"Grand [email protected]@@###\""] = () => Assert.That(TestValue, Is.EqualTo("Grand [email protected]@@###"));
58        }
59    }
60}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in Child

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)