How to use a_context method of NSpec.Tests.WhenRunningSpecs.BeforeAndAfter.BaseSpec class

Best NSpec code snippet using NSpec.Tests.WhenRunningSpecs.BeforeAndAfter.BaseSpec.a_context

Run NSpec automation tests on LambdaTest cloud grid

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

inheritance.cs

Source: inheritance.cs Github

copy
1using FluentAssertions;
2using NUnit.Framework;
3
4namespace NSpec.Tests.WhenRunningSpecs.BeforeAndAfter
5{
6    [TestFixture]
7    public class inheritance : when_running_specs
8    {
9        class BaseSpec : sequence_spec
10        {
11            void before_all()
12            {
13                sequence = "A";
14            }
15
16            void before_each()
17            {
18                sequence += "C";
19            }
20
21            void after_each()
22            {
23                sequence += "F";
24            }
25
26            void after_all()
27            {
28                sequence += "H";
29            }
30        }
31
32        class DerivedSpec : BaseSpec
33        {
34            void a_context()
35            {
36                beforeAll = () => sequence += "B";
37
38                before = () => sequence += "D";
39                specify = () => Assert.That(true, Is.True);
40                after = () => sequence += "E";
41
42                afterAll = () => sequence += "G";
43            }
44        }
45
46        [SetUp]
47        public void setup()
48        {
49            Run(typeof(DerivedSpec));
50        }
51
52        [Test]
53        public void before_alls_at_every_level_run_before_before_eaches_from_the_outside_in()
54        {
55            DerivedSpec.sequence.Should().StartWith("ABCD");
56        }
57
58        [Test]
59        public void after_alls_at_every_level_run_after_after_eaches_from_the_inside_out()
60        {
61            DerivedSpec.sequence.Should().EndWith("EFGH");
62        }
63    }
64}
Full Screen

async_inheritance.cs

Source: async_inheritance.cs Github

copy
1using FluentAssertions;
2using NUnit.Framework;
3using System.Threading.Tasks;
4
5namespace NSpec.Tests.WhenRunningSpecs.BeforeAndAfter
6{
7    [TestFixture]
8    [Category("Async")]
9    public class async_inheritance : when_running_specs
10    {
11        class BaseSpec : sequence_spec
12        {
13            async Task before_all()
14            {
15                await Task.Run(() => sequence = "A");
16            }
17
18            async Task before_each()
19            {
20                await Task.Run(() => sequence += "C");
21            }
22
23            async Task after_each()
24            {
25                await Task.Run(() => sequence += "F");
26            }
27
28            async Task after_all()
29            {
30                await Task.Run(() => sequence += "H");
31            }
32        }
33
34        class DerivedClass : BaseSpec
35        {
36            void a_context()
37            {
38                beforeAllAsync = async () => await Task.Run(() => sequence += "B");
39
40                beforeAsync = async () => await Task.Run(() => sequence += "D");
41                specify = () => Assert.That(true, Is.True);
42                afterAsync = async () => await Task.Run(() => sequence += "E");
43
44                afterAllAsync = async () => await Task.Run(() => sequence += "G");
45            }
46        }
47
48        [SetUp]
49        public void setup()
50        {
51            Run(typeof(DerivedClass));
52        }
53
54        [Test]
55        public void before_alls_at_every_level_run_before_before_eaches_from_the_outside_in()
56        {
57            DerivedClass.sequence.Should().StartWith("ABCD");
58        }
59
60        [Test]
61        public void after_alls_at_every_level_run_after_after_eaches_from_the_inside_out()
62        {
63            DerivedClass.sequence.Should().EndWith("EFGH");
64        }
65    }
66}
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

Trigger a_context code on LambdaTest Cloud Grid

Execute automation tests with a_context on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

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)